Solved

How to I split the string in VB.NET?

Posted on 2004-09-14
10
207 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ - C# to VB convertion 12 56
fso.FolderExists("\\server\HiddenFolder$") 4 65
Vb. Net application freezes 9 46
Write to file when application closes (by logoff) - VB.NET 1 31
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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