Solved

How to I split the string in VB.NET?

Posted on 2004-09-14
10
205 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now