Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

extracting a string within a string

hi,
Could any one write me code to extracta string within a string by identifying the end of the string to be extracted with a space.
eg:-"I am here"
then i have to extrac the word "I"
0
rtananthan
Asked:
rtananthan
1 Solution
 
rtananthanAuthor Commented:
Please answer this quickly as possible
0
 
Éric MoreauSenior .Net ConsultantCommented:
is this as simple as:
msgbox replace("I am here", "I", "")
0
 
bistricaCommented:
dim a as Array
dim s as String
a=Split(s, vbSpace)
msgbox a(0) 'I
...
msgbox a(2) '"here"

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ViazoomCommented:
Use Split statement.
It splits string into an array.
You can use it like this:

 Dim MyString As String
 Dim SplitedArray As Variant   'Split-function transformes the variant to array later

 MyString = "I am here"
 SplitedArray = Split(MyString)  'If no delimiter is given, the space " " is used
 
 This gives:
 SplitedArray(0) = "I"
 SplitedArray(1) = "am"
 SplitedArray(2) = "here"
 
 A script for finding "here" could look like this:

    Dim myArray As Variant
    Dim StringToFind As String

    Dim i As Integer
    myString = "I am here"
    StringToFind = "am"
    SplitedArray = Split(myString)  'If no delimiter is given, the space " " is used

    For i = LBound(SplitedArray) To UBound(SplitedArray)
        If SplitedArray(i) = StringToFind Then
            Text1.Text = SplitedArray(i) 'where Text1 is the outputfield. Could be returned to a simpla string as well
        End If
    Next
0
 
robertleesCommented:
to output the first word,

debug.print left(strText & " ", instr(strText, " ")-1)
0
 
CleanupPingCommented:
Hi rtananthan,
This old question (QID 20568018) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept Viazoom's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now