|
-
December 17th, 2003, 12:48 PM
#1
Filtering a String
Whats the best way to go about filtering out text from a String (1 line)
For example, I need to grab "CP6111DYSXB759" from the following line (There are always 4 spaces at the beginning of the line, but the text after is varys in length). Im thinking maybe the Trim function, and I know how to remove the starting spaces, it's the crap at the end I'm not sure of.
CP6111DYSXB759 <00> UNIQUE Registered
-
December 17th, 2003, 01:46 PM
#2
There must be a key string you know where to end. In your example, it should be "<00>". Then you can find out the position of "<00>" and get the sub-string before that position. Is it what you want?
Sonny
-
December 17th, 2003, 02:05 PM
#3
Thats exactly what I'm looking for, however the "<00>" can also change, so " <" would be the best bet. Which function will give me the pos of that sub?
-
December 17th, 2003, 02:06 PM
#4
You might look at the Split method, as long as the substring you're looking for ends with a space... IndexOf would also work to find the first deliminator/space...
bytz
--This signature left intentionally blank--
-
December 17th, 2003, 02:09 PM
#5
Originally posted by High_D
Thats exactly what I'm looking for, however the "<00>" can also change, so " <" would be the best bet. Which function will give me the pos of that sub?
You should be able to use split or indexof with the '<' or the space.
bytz
--This signature left intentionally blank--
-
December 17th, 2003, 05:08 PM
#6
you can also use a RegEx and looking from the begin to a mark which not is a char or a number.
-
December 18th, 2003, 12:32 PM
#7
Can you spot the new line?
Code:
else if(split[p]=="=")
{
nbtStats += "\t" + split[p+1].TrimEnd(new Char[] {' ','\n'});
nbtStats += this.WhoOwnsThisMAC(split[p+1].TrimEnd(new Char[] {' ','\n'}));
}
This is the output
144.250.247.42 DL130JZ11 00-08-74-2B-13-94
Dell Computer Corp.
It seems to add a new line feed after the MAC is printed...If I just print out "test" after the mac it also jumps to the next line (so it's not a word wrap or that line itself, it must be the MAC line).
Any suggestions?
-
December 18th, 2003, 12:46 PM
#8
I cut my losses and SubStringed it... 
Code:
nbtStats += "," + split[p+1].Substring(0,split[p+1].Length-6);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|