views:

1673

answers:

3

I have an application in VB.NET which gets "String" data from the database. This String has data which looks as below:

"This is the update:
I have an issue with the application"

I need only part of the data, that comes after the new line i.e. "I have an issue with the application".

For this I am trying to search the position using INSTR where the string has data in a new line. I tried many options but they don't work.

I used "vbCrLf", Chr(13), "\r\n", "\n", "<br/>", Environment.NewLine but none of them work.

Can some one help how I can get the data I need????

A: 

The newline character can be represented either by just a newline character (Chr(10)) or by a carriage return/linefeed pair (Chr(13) + Chr(10)). Depending on the source of the data this may of course vary. One way to achieve this is to make a string split on those two characters with the option to remove empty elements, throw away the first one and join the others together with newlines in between them:

ReadOnly separators As Char() = New Char() {Chr(10), Chr(13)}
Private Function StripFirstLine(ByVal input As String) As String
    Dim parts() As String = input.Split(separators, StringSplitOptions.RemoveEmptyEntries)

    If parts.Length > 1 Then
        Return String.Join(Environment.NewLine, parts, 1, parts.Length - 1)
    Else
        Return input
    End If

End Function
Fredrik Mörk
It't CR+LF (Char(13) + Char(10)), not the other way around.
Guffa
It worked...thank you
@Guffa: you are right of course; flipped it around. Must be the heat.
Fredrik Mörk
In vb.net, you can also use the individual vbCr and vbLf constants, rather than having to call the Chr() function.
Joel Coehoorn
+1  A: 

Use vbCrLf and not "vbCrLf"

It may also be that you have only line feeds or only carrige returns so using Chr(10) and Chr(13) may also be a better option.

Thies
thank you it works
+1  A: 

I don't think I'm adding much to this discussion but for what it's worth... you can also use "ControlChars" as in "ControlChars.CrLf".

ControlChars @ MSDN

Richard