?
Solved

How to I split the string in VB.NET?

Posted on 2004-09-14
10
Medium Priority
?
221 Views
Last Modified: 2010-04-23
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
Comment
Question by:balamgn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12053916
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 12053969
       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
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 375 total points
ID: 12053985
or  something like

Dim s As String = "mail       A     98.122.233.33"
Dim g As String = s.Substring(0, 4)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12054043
or the "old" way

        g = Microsoft.VisualBasic.Right(s, 13)   '= 98.122.233.33
        g = Microsoft.VisualBasic.Left(s, 4)       '= mail
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12054363
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
 

Author Comment

by:balamgn
ID: 12054487
Thanks guys! I got it.
0
 

Author Comment

by:balamgn
ID: 12054813
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12054880
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
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 12054977
did you try bramsquad's or mine ?
0
 

Author Comment

by:balamgn
ID: 12054996
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question