[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
Re: searcing between two word
Quote:
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?
Re: searcing between two word
Quote:
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
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.
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
Re: searcing between two word
Quote:
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!:thumb:
Sorry me, in other case, for my bad english:blush::o
ops... note:
I have 2 friends argentinos, but they live in Italy from 40 years :wave:;)
Re: searcing between two word
Quote:
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.