Way to find a String after spaces?

jimbo2k

Member
Joined
Mar 31, 2004
Messages
16
Location
ON,Canada
Any Help would be greatly appreciated

I need a way to find a number after either one space, or two.
Ex: Number1: 555 <---one space
Ex2: Number1: 666 <---two spaces

I know how I could do each one independantly, but Id need it all in one code.
This code will find the number 555 in the first scenerio (one space) but wont work for the second scenerio (with two spaces):

Code:
Position1 = InStr(FirstString, "Number1: ") finds start position by finding "Number1: "
        EndPosition = InStr(Position1 + 9, FirstString, " ") finds end position by finding the space after the number: (use +9 because the word "Number1: " is 9 characters)
        Label1.Text = Mid(FirstString, Position1 + 9, EndPosition - Position1 - 9) inbetween start and end is the number

PS: how do I format using .net?
 
Try using Replace:
FirstString = FirstString.Replace(" ", " ")

Also, consider using .NET System methods instead of VB compatibility methods.
InStr( S, other args ) is now S.IndexOf( other args )
Mid(S, other args ) is now S.SubString( other args), where the string is now 0-based instead of 1-based.

To format in .NET, use .ToString()
But, Mid and .SubString both return strings... it would be redundant to convert the string to a string. :)
 
Iceplug said:
Try using Replace:
FirstString = FirstString.Replace(" ", " ")

Also, consider using .NET System methods instead of VB compatibility methods.
InStr( S, other args ) is now S.IndexOf( other args )
Mid(S, other args ) is now S.SubString( other args), where the string is now 0-based instead of 1-based.

To format in .NET, use .ToString()
But, Mid and .SubString both return strings... it would be redundant to convert the string to a string. :)

Thanks, Ill have a look into what you suggested.

As for formatting in .NEt i meant for the forum, instead of VB tags what are the VB.net tags? :p
Thanks again!
 
Back
Top