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
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
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.
Assuming there are blank spaces before and after the string like in your example:
Usage: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
Instr() returns the a String position inside another stringCode:MsgBox getString("222 AAAAA a12312312 BBBBBB 333", "AAAAA", "BBBBBB")
Mid() returns an String inside another, given the start position and its lengh