Solved

How to I split the string in VB.NET?

Posted on 2004-09-14
10
216 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:Desp
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 125 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
Technology Partners: 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:Desp
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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