locked
trim at end of line RRS feed

  • Question

  • please help....

    ive got the following code:

    If gamecam_exists = 1 Then

    StringToFind = "set gc_motd " + Chr(34)

    iStartFoundPosition = StringToSearch.IndexOf(StringToFind)

    If iStartFoundPosition > 0 And StringToSearch.Length > 0 Then

    str1 = StringToSearch.Substring(iStartFoundPosition + StringToFind.Length, StringToSearch.Length - (iStartFoundPosition + StringToFind.Length))

    str1 = str1.Remove(str1.IndexOf(Chr(34)))

    Else

    str1 = "0"

    End If

    gc_motd.Text = str1

    End If

    it basicly looks in a file called server.cfg in the folder StringToSearch; pulls out everything past StringToFind and sticks it into a single line textbox. then chops it off at the first " it comes accross. the new line is represented by 2 little boxes. now what i need help on is i cannot figure out how to get it to chop it off at that new line symbol so i dont have to add the Dquote mark. its not needed anyway. how would i do this?

    Sunday, October 1, 2006 12:00 AM

Answers

  • ok i figured it out! thank you for letting me know of the environment.newline :)

    this is the line syntax that worked:

    str1 = str1.Remove(str1.IndexOf(Environment.NewLine))

    Wednesday, October 4, 2006 4:35 PM

All replies

  • you could just do a String.Replace to replace the character in question with nothing. Example:

     

    Dim theString as String = ""hello""

     

    that on its own would produce, WITH quotes:

    "hello"

    to "chop" off the quotes:

     

    Dim theFinalString as String = theString.Replace("""", String.Empty)

     

    does this help/work for you?

    Re-reading your original post, the square boxes usually indicate that there is a newline being put into the textbox and your textbox does not allow multiple lines - this can be enabled as a MultiLine in the textbox properties. So I guess maybe, but not guarenteed, you could just do a Replace on the Environment.NewLine:

    theFinalString = theString.Replace(Environment.NewLine, String.Empty)

    you can "chop" off everything after the Newline symbol also by just getting everything after the newline symbol using the SubString() method or get everything before it again using the SubString() method but telling it to keep going until it gets to the NewLine symbol (technically this last part would be for the length property, so you would have to do some tinkering with strings again, so something like get the index of where the newline begins and substract it with the length of the string? I'm really not sure)

     

    as you know now, doing string parsing is really...not so great. Perhaps there is another way?

     

    Sunday, October 1, 2006 12:58 AM
    Moderator
  • i tried your method:
    theFinalString = theString.Replace(Environment.NewLine, String.Empty)

    but it didnt work? am i doing something wrong? heres another example where i need to chop off at end of line instead at quotes.

    StringToFind = "dmflags " + Chr(34)

    iStartFoundPosition = StringToSearch.IndexOf(StringToFind)

    If iStartFoundPosition > 0 And StringToSearch.Length > 0 Then

    str1 = StringToSearch.Substring(iStartFoundPosition + StringToFind.Length, StringToSearch.Length - (iStartFoundPosition + StringToFind.Length))

    'str1 = str1.Remove(str1.IndexOf(Chr(34)))

    str1 = str1.Replace(Environment.NewLine, String.Empty)

    dmflags_disp.Text = str1

    ------------end of snippet---------

    doesnt work; outputs this:
    65533"[][]set public 1[][]set logfile 3[][]s

    instead of this:
    65533"

    its in the file (server.cfg) as:
    dmflags "65533"

    the quotes dont need to be there since there will not be any spaces.

    anyone know of a solution?

    Monday, October 2, 2006 6:35 PM
  • ok i figured it out! thank you for letting me know of the environment.newline :)

    this is the line syntax that worked:

    str1 = str1.Remove(str1.IndexOf(Environment.NewLine))

    Wednesday, October 4, 2006 4:35 PM