Parsing Question! :) help needed bigtime...

I have an issue where data in cells could look like a few different ways:

14.83
140.83
1140.8
1140.83
1140.83(Session: 84848)

Basically, I'm drawing a blank on how to parse the data. Obviously the data string length is dynamic. My main goal is to find IF the cell has the "(Session: 84848)" then delete that, but keep the 1140.83. And it needs to be dynamic...

Any thoughts? Would I use the InStr?

I'm stuck!

TIA!

-Scott
scott@fightingzero.com

[477 byte] By [fightingzero] at [2008-2-4]
# 1
well, you understand that the data must conform to some resemblance of order to be parsed. Having said that, based on your sample data, probably the simplest method would be to use the split function with a "(" as a delimiter. After that, your relevant data would be in the 0th element of the resultant array...get it?
ex.
dim MyData as string = "1140.83(Session: 84848)"
dim a() as string = MyData.Split(cchar("(")) '<<=that looks awkward as hell
dim MyRelevantData as string = a(0)
HTH
kevin
kebo at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
If you are just worried about stripping off that part then I would use:


If String.IndexOf("(") >= 0 Then

String = String.Substring(0, String.LastIndexOf("("))

End If


JoeSmugeresky at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
o yes... much better than split. I guess my and hard grained days of vb6 are showing.Big Smile
kebo at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...