-
Feb 26th, 2012, 01:14 PM
#1
Thread Starter
PowerPoster
[RESOLVED] searcing between two word
I have in a txt file a line similar:
...
AAAAA a12312312 BBBBBB
....
I need to get only this part: a12312312
in effect i need to get value between to other string part, how to?
note:
the postion in string of AAAAA and BBBBBB is variable
-
Feb 26th, 2012, 02:28 PM
#2
Addicted Member
Re: searcing between two word
Originally Posted by luca90
I need to get only this part: a12312312
the postion in string of AAAAA and BBBBBB is variable
Is the string you want to get ALWAYS the same string?
-
Feb 26th, 2012, 02:34 PM
#3
Thread Starter
PowerPoster
Re: searcing between two word
Originally Posted by B61Nuke
Is the string you want to get ALWAYS the same string?
If your dubt is about that "a12312312", no!
Is only an example...
i can have a variable string with a variable lenght from AAAAAAA and BBBBBBBB
-
Feb 26th, 2012, 02:53 PM
#4
Re: searcing between two word
You may want to try Split() with space as the seperator which will break the string into an array. From your example element 1 of the array will hold the data you want.
Or you can use a combination of Instr() and Mid() to get the data.
-
Feb 26th, 2012, 03:10 PM
#5
Re: searcing between two word
Assuming there are blank spaces before and after the string like in your example:
Code:
Private Function getString(s As String, a As String, b As String)
Dim s_start As Long, s_end As Long
s_start = InStr(1, s, a) + Len(a) + 1
s_end = InStr(1, s, b) - 2
getString = Mid(s, s_start, s_end + 1 - s_start)
End Function
Usage:
Code:
MsgBox getString("222 AAAAA a12312312 BBBBBB 333", "AAAAA", "BBBBBB")
Instr() returns the a String position inside another string
Mid() returns an String inside another, given the start position and its lengh
-
Feb 26th, 2012, 03:20 PM
#6
Thread Starter
PowerPoster
Re: searcing between two word
Originally Posted by jcis
Assuming there are blank spaces before and after the string like in your example:
Code:
Private Function getString(s As String, a As String, b As String)
Dim s_start As Long, s_end As Long
s_start = InStr(1, s, a) + Len(a) + 1
s_end = InStr(1, s, b) - 2
getString = Mid(s, s_start, s_end + 1 - s_start)
End Function
Usage:
Code:
MsgBox getString("222 AAAAA a12312312 BBBBBB 333", "AAAAA", "BBBBBB")
Instr() returns the a String position inside another string
Mid() returns an String inside another, given the start position and its lengh
IS PERFECT!
Sorry me, in other case, for my bad english
ops... note:
I have 2 friends argentinos, but they live in Italy from 40 years
Last edited by luca90; Feb 26th, 2012 at 03:24 PM.
-
Feb 26th, 2012, 07:41 PM
#7
Addicted Member
Re: searcing between two word
Originally Posted by luca90
If your dubt is about that "a12312312", no!
Is only an example...
i can have a variable string with a variable lenght from AAAAAAA and BBBBBBBB
I was only asking and used your example you posted. I know your string was not the same as the example. Your answer about the variable string and the length was critical info to get you the correct answer. thats why I had asked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|