Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 I'd 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):

 

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?

  • Leaders
Posted

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, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted
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!

  • Leaders
Posted

The VB.NET tags are

 ;).

Similarly, C# tags are [code=csharp].

I'm working on a syntax highlighter for myself in .NET :).

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • Leaders
Posted
Because they aren't working yet. :o

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...