Friday, 15 February 2013

String split by Newline in VB.NET


String split by Newline in VB.NET

if String is in this format
     Dim  str as String = "1)ABS
2)SIGN
3)MOD
4)FLOOR
5)CEIL
6)ROUND
7)EXP
8)LOG
9)LOG10
10)POW
11)POWER
12)SQRT
13)PI
14)COS
15)SIN
16)TAN"

Split string by new line -> then  by  ')'  get exact Strings 


1) Split by Newline
            User can split by  "\r\n"   or System.Environment.NewLine

        Dim final As String = String.Empty
           Dim array() As String = str.Split(New String() {"\r\n"}
, StringSplitOptions.RemoveEmptyEntries)
           Dim s As String
           For Each s In array
               Console.WriteLine(s)
               final+=s.Split(New Char()
               {
                   ")"c
               }
, StringSplitOptions.RemoveEmptyEntries)(1)+" "
           Next
 
 OUTPUT
1)ABS
2)SIGN
3)MOD
4)FLOOR
5)CEIL
6)ROUND
7)EXP
8)LOG
9)LOG10
10)POW
11)POWER
12)SQRT
13)PI
14)COS
15)SIN
16)TAN
 
2) Split String by  ')'  character

            Dim finalwords() As String = final.Split(New String() {" "}
, StringSplitOptions.RemoveEmptyEntries)
           Array.Sort(finalwords)
           Dim i As Integer =  0
           Dim f As String
           For Each f In finalwords
               Console.Write(f + "\t")
           Next

FINAL OUTPUT:
ABS SIGN MOD FLOOR CEIL ROUND EXP LOG LOG10 POW POWER SQRT PI COS SIN TAN
ABS     CEIL    COS     EXP     FLOOR   LOG     LOG10   MOD     PI      POW
POWER   ROUND   SIGN    SIN     SQRT    TAN

Tags:String split by Newline in VB.NET,String split by '\r\n',String Split by System.Environment.NewLine. Split Strings in VB.NET,Split a String on Line Breaks,Split a String on carriage Return

No comments:

Post a Comment