VB.net new Line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gangreen
    New Member
    • Feb 2008
    • 98

    VB.net new Line

    I recieve a string, which consists of multiple lines, from a UDP connection.
    (It's that java program I'm translating for those who have read my other topics)

    Now, I need to split this string in seperate lines, but this does not seem to work.
    In the java program "\n" is used as delimiter to split the string, but when I try to split (in the translated vb.net program) using VbNewLine it does not work. I also tried VbCr and VbCrLf...

    I did an experiment: I used the InStr to see if VbNewLine or whatever is found in the string. Apparently none of them are found.

    Are there more options to create new lines I haven't checked?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You could use .Split() on the string and supply the '\n' character as what to split on?

    Comment

    • Sick0Fant
      New Member
      • Feb 2008
      • 121

      #3
      Originally posted by Plater
      You could use .Split() on the string and supply the '\n' character as what to split on?
      '\n' won't work in VB, will it?

      Since you're working in .NET, you can assume ASCII values for characters. So do something like:

      MyString.Split( Convert.ToChar( 13))

      Comment

      • Gangreen
        New Member
        • Feb 2008
        • 98

        #4
        Originally posted by Plater
        You could use .Split() on the string and supply the '\n' character as what to split on?
        No that won't work. (I tried anyway)
        The "\n" is the equivalent of VbNewLine in java....

        Comment

        • Gangreen
          New Member
          • Feb 2008
          • 98

          #5
          Originally posted by Sick0Fant
          MyString.Split( Convert.ToChar( 13))
          InStr(myString, Convert.ToChar( 13)) returns 0 ...

          Comment

          • Sick0Fant
            New Member
            • Feb 2008
            • 121

            #6
            Originally posted by Gangreen
            InStr(myString, Convert.ToChar( 13)) returns 0 ...
            Maybe they are carriage returns, in which case you'd use 10 instead of 13.

            If that's not in the string, then I don't know how it's delimited.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Stop using InStr, start using .NET syntax.

              mystring.IndexO f('\n') if that doesn't return a value >-1 then there is no \n's in there.

              I have a theory on what might be happening. Your UDP is probably getting in a byte[] right? ( byte() whatever they call it in vb)
              How are you converting it to a string?

              Comment

              • Gangreen
                New Member
                • Feb 2008
                • 98

                #8
                Originally posted by Sick0Fant
                Maybe they are carriage returns, in which case you'd use 10 instead of 13.

                If that's not in the string, then I don't know how it's delimited.
                Console.WriteLi ne("Index: " & queryResult.Ind exOf(Convert.To Char(10)))

                prints out Index 80!
                yes! It's carriage return apparently, thank you.

                @Plater, Thanx for the help, but please explain why IndexOf is better than InStr?

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  It's an actual .NET function. If you're going to program in managed code (instead of vb6 for example) why not use it? Plus it's easier to read since it matches with other .NET code, so for future questions people won't have to decipher things like Mid(), InStr(), etc, etc.

                  Comment

                  Working...