Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

How can I split in two parts Original line ? Thanks.


original line = HD_PRS22_S_DL 33000


Textbox1 thus = HD_PRS22_S_DL

Textbox2 thus = 33000



Not: HD_PRS22_S_DL < one tab space > 33000
Posted
Comments
Peter Leow 14-Dec-13 20:27pm    
Is there a space between 'L' and '3'?

The method that I would use is the shared Split method on the string class. This method has several overloads, but there is one that does become apparent in the intellisence suggestions because it is a special case where the split items array is null (Nothing). This tells the method to use whitespace characters as the split points. The exact list of characters used depends on the version of the .Net framework. For .Net 4.0 and above its is the same list used by the Char.IsWhiteSpace method [^] For .Net 3.5 and below see this list in the remarks section here[^].

C#
Dim str As String = "1" & vbLf & "2" & vbTab & "3" & vbCrLf & "4 5"
Dim parts() As String = str.Split(New Char() {}, System.StringSplitOptions.RemoveEmptyEntries)
Parts will be an array comprising five strings. The second parameter in the method, (System.StringSplitOptions.RemoveEmptyEntries, tells the Split method to delete e,mptry entries that could be created by consecutive whitespace characters such as the VBCrLF (carriage return and linefeed) shown in the example code.
 
Share this answer
 
This sample code assumes that a single space is the delimiter between the two subparts of the string.
VB
Dim strInput As String = "HD_PRS22_S_DL 33000"
Dim x As Integer = strInput.IndexOf(" ") ' Assumes space is the delimiter
Console.WriteLine(strInput.Substring(0, x))
Console.WriteLine(strInput.Substring(x + 1))


This sample code assumes that a single Tab character is the delimiter between the two subparts of the string.
VB
Dim strInput As String = "HD_PRS22_S_DL" & vbTab & "33000"
Dim x As Integer = strInput.IndexOf(vbTab) ' Assumes Tab is the delimiter
Console.WriteLine(strInput.Substring(0, x))
Console.WriteLine(strInput.Substring(x + 1))


This sample code assumes that one or more spaces are the delimiter between the two subparts of the string.
VB
Dim strInput As String = "HD_PRS22_S_DL" & SPACE(5) & "33000"
Dim x As Integer = strInput.IndexOf(" ") ' Assumes space is the delimiter
Console.WriteLine(strInput.Substring(0, x).Trim)
Console.WriteLine(strInput.Substring(x + 1).Trim)


This sample code assumes that a Tab character is the delimiter but there could be one or more spaces between the two subparts of the string.
VB
Dim strInput As String = "HD_PRS22_S_DL" & SPACE(2) & vbTab & SPACE(2) & "33000"
Dim x As Integer = strInput.IndexOf(vbTab) ' Assumes Tab is the delimiter
Console.WriteLine(strInput.Substring(0, x).Trim)
Console.WriteLine(strInput.Substring(x + 1).Trim)
 
Share this answer
 
v6
Comments
EssenceGold 15-Dec-13 7:10am    
Thank you very much my friend. Problem solved. Good Work.
There are a number of ways to achieve it. Check this out:
www.dotnetperls.com/split-vbnet[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900