CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2003
    Posts
    133

    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

  2. #2
    Join Date
    Sep 2002
    Posts
    19
    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

  3. #3
    Join Date
    Oct 2003
    Posts
    133
    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?

  4. #4
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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--

  5. #5
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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--

  6. #6
    Join Date
    May 2003
    Location
    Germany
    Posts
    936
    you can also use a RegEx and looking from the begin to a mark which not is a char or a number.

  7. #7
    Join Date
    Oct 2003
    Posts
    133
    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?

  8. #8
    Join Date
    Oct 2003
    Posts
    133
    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
  •  





Click Here to Expand Forum to Full Width

Featured