Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse out string

Status
Not open for further replies.

huobaji

Technical User
Sep 20, 2010
23
US
I need to parse out multiple strings and each string can be different

example:

15GIRLCLUB General Help Needed 1.200
15BOYSCLUB General Help 1.200

I would like to parse out like this

15GIRLCLUB
General Help Needed
1.200

15BOYSCLUB
General Help
1.200

I tried using this but its not getting what I need. I would like the title to parse out up until it gets to a number or if there is another way to do it I would appreciate it any help thanks
CID = Left(AP4, 10)
Title = Trim(mid(AP4,11, 23))
 
How similar are your strings? Is there always 1 word at the beginning and 1 number at the end that you want to parse out?
 
example

15GIRLCLUB General Help Needed 1.200 hr
15XXXXCLUB General BBBB Needed XXX 4.200 hr
15AAAACLUB ZZZZZZZ BBBB Needed XXXXXX 4.200 hr
15FFFFCLUB SSSFFFF BBB Needed XXXXXX 4.200 hr

want to get the first 10 in the string: 15GIRLCLUB
then the next all the way up to the number: General Help Needed
third the number: 1.200

yes the beginning would be 1 word
 
Maybe something like this?
Code:
string01 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"15GIRLCLUB General Help Needed 1.200"[/color]
string02 [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"15BOYSCLUB General Help 1.250"[/color]

wscript[COLOR=#804040][b].[/b][/color]echo string01 [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]" -> "[/color]
[COLOR=#804040][b]call[/b][/color] decompose_strings[COLOR=#804040][b]([/b][/color]string01[COLOR=#804040][b])[/b][/color]
wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]vbCr[/color]

wscript[COLOR=#804040][b].[/b][/color]echo string02 [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]" -> "[/color]
[COLOR=#804040][b]call[/b][/color] decompose_strings[COLOR=#804040][b]([/b][/color]string02[COLOR=#804040][b])[/b][/color]

[COLOR=#0000ff]'---------------------------------------------------[/color]
[COLOR=#804040][b]sub[/b][/color] decompose_strings[COLOR=#804040][b]([/b][/color]search_string[COLOR=#804040][b])[/b][/color]
   str_list [COLOR=#804040][b]=[/b][/color] [COLOR=#a020f0]split[/color][COLOR=#804040][b]([/b][/color]search_string[COLOR=#804040][b])[/b][/color]

   first[COLOR=#804040][b]=[/b][/color]str_list[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]0[/color][COLOR=#804040][b])[/b][/color]

   middle [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
   [COLOR=#804040][b]for[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color] [COLOR=#804040][b]to[/b][/color] [COLOR=#008080]ubound[/color][COLOR=#804040][b]([/b][/color]str_list[COLOR=#804040][b])-[/b][/color][COLOR=#ff00ff]1[/color]
     middle [COLOR=#804040][b]=[/b][/color] middle [COLOR=#804040][b]&[/b][/color] str_list[COLOR=#804040][b]([/b][/color]j[COLOR=#804040][b])[/b][/color] [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]" "[/color]
   [COLOR=#804040][b]next[/b][/color]
   middle [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]rtrim[/color][COLOR=#804040][b]([/b][/color]middle[COLOR=#804040][b])[/b][/color]

   last[COLOR=#804040][b]=[/b][/color]str_list[COLOR=#804040][b]([/b][/color][COLOR=#008080]ubound[/color][COLOR=#804040][b]([/b][/color]str_list[COLOR=#804040][b]))[/b][/color]

   wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"First : '"[/color] [COLOR=#804040][b]&[/b][/color] first [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"'"[/color]
   wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"Middle: '"[/color] [COLOR=#804040][b]&[/b][/color] middle [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"'"[/color]
   wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"Last  : '"[/color] [COLOR=#804040][b]&[/b][/color] last [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"'"[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]
Code:
c:\Users\Roman\Work>cscript /NoLogo extract_str.vbs
15GIRLCLUB General Help Needed 1.200 ->
First : '15GIRLCLUB'
Middle: 'General Help Needed'
Last  : '1.200'

15BOYSCLUB General Help 1.250 ->
First : '15BOYSCLUB'
Middle: 'General Help'
Last  : '1.250'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top