Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

How to I split the string in VB.NET?

Any one help me to split a particular sting from the right or left side in the string. For example I want to split "mail" from the string "mail       A     98.122.233.33"

Thanks in advance.
0
balamgn
Asked:
balamgn
  • 3
  • 3
  • 2
  • +2
1 Solution
 
HemanthaKumarCommented:
0
 
Fahad MukhtarDistinguished EngineerCommented:
       Dim s As String = "mail       A     98.122.233.33"
        Dim StringToSplit = "mail"
        s = s.Substring(s.IndexOf(StringToSplit), StringToSplit.length)
        MessageBox.Show(s)                                           ' s = "mail" now
0
 
RonaldBiemansCommented:
or  something like

Dim s As String = "mail       A     98.122.233.33"
Dim g As String = s.Substring(0, 4)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RonaldBiemansCommented:
or the "old" way

        g = Microsoft.VisualBasic.Right(s, 13)   '= 98.122.233.33
        g = Microsoft.VisualBasic.Left(s, 4)       '= mail
0
 
bramsquadCommented:
or the "new" way :)

        Dim str As String = "mail       A     98.122.233.33"
        Dim strArray() As String = str.Split()

        MsgBox(strArray(0))

~b
0
 
balamgnAuthor Commented:
Thanks guys! I got it.
0
 
balamgnAuthor Commented:
Hi RonaldBiemans,

While I try your code, I got the folloing error message.

"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Index and length must refer to a location within the string."
0
 
RonaldBiemansCommented:
could you post what you did, because the error means that either the index or the lenght don't match your string

like

Dim s As String = "hello"
Dim g As String = s.Substring(10, 4)

the s has a lenght of 5 so 10 would cause that error
0
 
Fahad MukhtarDistinguished EngineerCommented:
did you try bramsquad's or mine ?
0
 
balamgnAuthor Commented:
Yes,  you are correct. My text file having many single line charecter and blank links. Thanks why i'm facing this errer. It is working now. Thanks for your help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now