?
Solved

extracting a string within a string

Posted on 2003-03-30
7
Medium Priority
?
227 Views
Last Modified: 2010-05-01
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
Comment
Question by:rtananthan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:rtananthan
ID: 8234216
Please answer this quickly as possible
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8234231
is this as simple as:
msgbox replace("I am here", "I", "")
0
 
LVL 4

Expert Comment

by:bistrica
ID: 8234251
dim a as Array
dim s as String
a=Split(s, vbSpace)
msgbox a(0) 'I
...
msgbox a(2) '"here"

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Accepted Solution

by:
Viazoom earned 1000 total points
ID: 8234354
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
 
LVL 1

Expert Comment

by:robertlees
ID: 8235658
to output the first word,

debug.print left(strText & " ", instr(strText, " ")-1)
0
 

Expert Comment

by:CleanupPing
ID: 8531318
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440568
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question