473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Need help Spliting a strings.

Hello,

I need to split:
2 1066 1.30 172.90 1065.9 -14.2 3.0 -13.3 0.1
3 1528 1.00 188.10 1527.8 -23.3 3.0 -20.9 0.1
4 2007 0.60 182.60 2006.7 -30.0 2.3 -25.9 0.1
5 2484 1.00 195.20 2483.7 -36.5 1.1 -30.5 0.1
6 2962 0.90 200.90 2961.6 -44.0 -1.3 -35.3 0.0
7 3104 1.50 237.50 3103.6 -46.1 -3.3 -35.8 0.7

Into

2
1066
1.30
172.90
1065.9
-14.2
3.0
-13.3
0.1

And do this for each Line.

I tried split(" "), but it did not work. I would like to parse from
non-space char to non-space char.
Thanks in advance for any help!!
Thanks,
Jack

May 11 '07 #1
8 1046
On May 11, 3:50 pm, "Jack" <j...@webfoxmail.comwrote:
Hello,

I need to split:

2 1066 1.30 172.90 1065.9 -14.2 3.0 -13.3 0.1
3 1528 1.00 188.10 1527.8 -23.3 3.0 -20.9 0.1
4 2007 0.60 182.60 2006.7 -30.0 2.3 -25.9 0.1
5 2484 1.00 195.20 2483.7 -36.5 1.1 -30.5 0.1
6 2962 0.90 200.90 2961.6 -44.0 -1.3 -35.3 0.0
7 3104 1.50 237.50 3103.6 -46.1 -3.3 -35.8 0.7

Into

2
1066
1.30
172.90
1065.9
-14.2
3.0
-13.3
0.1

And do this for each Line.

I tried split(" "), but it did not work. I would like to parse from
non-space char to non-space char.
Thanks in advance for any help!!
Thanks,
Jack
I assume you actually did Split(variablename, " ")?

Actually, Split(varibablename) is equivalen, as the space character is
the default delimiter for the Space function.

May 11 '07 #2
On May 11, 2:50 pm, "Jack" <j...@webfoxmail.comwrote:
Hello,

I need to split:

2 1066 1.30 172.90 1065.9 -14.2 3.0 -13.3 0.1
3 1528 1.00 188.10 1527.8 -23.3 3.0 -20.9 0.1
4 2007 0.60 182.60 2006.7 -30.0 2.3 -25.9 0.1
5 2484 1.00 195.20 2483.7 -36.5 1.1 -30.5 0.1
6 2962 0.90 200.90 2961.6 -44.0 -1.3 -35.3 0.0
7 3104 1.50 237.50 3103.6 -46.1 -3.3 -35.8 0.7

Into

2
1066
1.30
172.90
1065.9
-14.2
3.0
-13.3
0.1

And do this for each Line.

I tried split(" "), but it did not work. I would like to parse from
non-space char to non-space char.
Thanks in advance for any help!!
Thanks,
Jack
What do you mean it did not work? Did you get an error? Are those
indeed spaces in between each number? Do you need to use them as
numbers, for calculations for example?

Dim numbers As String() = oneOfYourStrings.Split(" ")

For Each number As String In numbers
Console.WriteLine(number)
Next

That should work. If you need to convert each one to a number, you
can try Decimal.TryParse, or Double.TryParse, etc.

Good Luck

May 11 '07 #3
Hello,

Thanks for the help, but I need to return just the Item with no Blank
string.

Thanks,

Jack

"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.com...
On May 11, 2:50 pm, "Jack" <j...@webfoxmail.comwrote:
>Hello,

I need to split:

2 1066 1.30 172.90 1065.9 -14.2 3.0 -13.3 0.1
3 1528 1.00 188.10 1527.8 -23.3 3.0 -20.9 0.1
4 2007 0.60 182.60 2006.7 -30.0 2.3 -25.9 0.1
5 2484 1.00 195.20 2483.7 -36.5 1.1 -30.5 0.1
6 2962 0.90 200.90 2961.6 -44.0 -1.3 -35.3 0.0
7 3104 1.50 237.50 3103.6 -46.1 -3.3 -35.8 0.7

Into

2
1066
1.30
172.90
1065.9
-14.2
3.0
-13.3
0.1

And do this for each Line.

I tried split(" "), but it did not work. I would like to parse from
non-space char to non-space char.
Thanks in advance for any help!!
Thanks,
Jack

What do you mean it did not work? Did you get an error? Are those
indeed spaces in between each number? Do you need to use them as
numbers, for calculations for example?

Dim numbers As String() = oneOfYourStrings.Split(" ")

For Each number As String In numbers
Console.WriteLine(number)
Next

That should work. If you need to convert each one to a number, you
can try Decimal.TryParse, or Double.TryParse, etc.

Good Luck
May 12 '07 #4
>
Thanks for the help, but I need to return just the Item with no Blank
string.
I'm not sure what you mean by this. The Split method does not return
any spaces. If you happen to have more than one consecutive space in
the original string, you could use the alternate overload and specify
the RemoveEmptyEntries option.

Please explain further what problem you are having with String.Split

Chris

May 14 '07 #5
On 11 mayo, 15:50, "Jack" <j...@webfoxmail.comwrote:
Hello,

I need to split:

2 1066 1.30 172.90 1065.9 -14.2 3.0 -13.3 0.1
3 1528 1.00 188.10 1527.8 -23.3 3.0 -20.9 0.1
4 2007 0.60 182.60 2006.7 -30.0 2.3 -25.9 0.1
5 2484 1.00 195.20 2483.7 -36.5 1.1 -30.5 0.1
6 2962 0.90 200.90 2961.6 -44.0 -1.3 -35.3 0.0
7 3104 1.50 237.50 3103.6 -46.1 -3.3 -35.8 0.7

Into

2
1066
1.30
172.90
1065.9
-14.2
3.0
-13.3
0.1

And do this for each Line.

I tried split(" "), but it did not work. I would like to parse from
non-space char to non-space char.
Thanks in advance for any help!!
Thanks,
Jack
Hi there,

It puts every single string in a array position (tCad) and keep a copy
of the original string:

Dim Cad As String = "2 1066 1.30 172.90 1065.9 -14.2 3.0 -13.3 0.1
"
Dim tmpCad As String
Dim tCad(20) As String
Dim i, a As Integer

tmpCad = Cad
i = 0
While Len(tmpCad) 0
a = InStr(tmpCad, " ", CompareMethod.Binary)
tCad(i) = Mid(tmpCad, 1, a - 1)
tmpCad = Mid(tmpCad, a + 1, Len(tmpCad))
i += 1
End While

Cheers

May 14 '07 #6
Hello,

How do I do that?

Thanks,

Jack

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...

Thanks for the help, but I need to return just the Item with no Blank
string.

I'm not sure what you mean by this. The Split method does not return
any spaces. If you happen to have more than one consecutive space in
the original string, you could use the alternate overload and specify
the RemoveEmptyEntries option.

Please explain further what problem you are having with String.Split

Chris
May 23 '07 #7
Sorry Need to split:

MWD 11409.00 3.00 298.30 N61.7 W 31 11404.89 144.51 N
76.99 W 123.27 145.33 301.99 5.08 1.81 -101.8 -5.8
15.4 112.5 3948.2 -928.9 105.9 1.8
4.0
MWD 11441.00 6.10 293.80 N66.2 W 32 11436.78 147.05 N
78.07 W 125.56 147.85 301.87 9.74 9.69 -14.06 -5.3
15.4 112.5 3950.7 -960.8 106.4 9.7
11.3
MWD 11473.00 8.60 294.00 N66.0 W 32 11468.52 151.14 N
79.73 W 129.30 151.91 301.66 7.81 7.81 0.62 -4.9
15.2 112.5 3954.8 -992.5 106.9 7.8
12.8
MWD 11505.00 10.60 294.90 N65.1 W 32 11500.07 156.48 N
81.94 W 134.16 157.20 301.42 6.27 6.25 2.81 -4.6
15.1 112.5 3960.1 -1024.1 107.5 6.2
14.0
MWD 11537.00 11.10 295.20 N64.8 W 32 11531.49 162.50 N
84.49 W 139.61 163.19 301.18 1.57 1.56 0.94 -4.4
15.0 112.5 3966.2 -1055.5 108.0 1.6
11.9
MWD 11570.00 12.40 296.40 N63.6 W 33 11563.80 169.22 N
87.42 W 145.66 169.88 300.97 4.01 3.94 3.64 -4.1
15.0 112.5 3972.9 -1087.8 108.6 3.9
14.5
P-Bit 11624.00 14.03 296.40 N63.6 W 54 11616.37 181.56 N
92.91 W 156.72 182.19 300.66 3.02 3.02 0.00 -3.8
15.1 112.5 3985.2 -1140.4 109.5 3.0
15.7

into Columns.

Thanks for you help,

Jack

"Jack" <jo***@webfoxmail.comwrote in message
news:72**********************************@microsof t.com...
Hello,

How do I do that?

Thanks,

Jack

"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>
Thanks for the help, but I need to return just the Item with no Blank
string.

I'm not sure what you mean by this. The Split method does not return
any spaces. If you happen to have more than one consecutive space in
the original string, you could use the alternate overload and specify
the RemoveEmptyEntries option.

Please explain further what problem you are having with String.Split

Chris
May 23 '07 #8
On May 23, 3:39 am, "Jack" <j...@webfoxmail.comwrote:
Sorry Need to split:

MWD 11409.00 3.00 298.30 N61.7 W 31 11404.89 144.51 N
76.99 W 123.27 145.33 301.99 5.08 1.81 -101.8 -5.8
15.4 112.5 3948.2 -928.9 105.9 1.8
4.0
MWD 11441.00 6.10 293.80 N66.2 W 32 11436.78 147.05 N
78.07 W 125.56 147.85 301.87 9.74 9.69 -14.06 -5.3
15.4 112.5 3950.7 -960.8 106.4 9.7
11.3
MWD 11473.00 8.60 294.00 N66.0 W 32 11468.52 151.14 N
79.73 W 129.30 151.91 301.66 7.81 7.81 0.62 -4.9
15.2 112.5 3954.8 -992.5 106.9 7.8
12.8
MWD 11505.00 10.60 294.90 N65.1 W 32 11500.07 156.48 N
81.94 W 134.16 157.20 301.42 6.27 6.25 2.81 -4.6
15.1 112.5 3960.1 -1024.1 107.5 6.2
14.0
MWD 11537.00 11.10 295.20 N64.8 W 32 11531.49 162.50 N
84.49 W 139.61 163.19 301.18 1.57 1.56 0.94 -4.4
15.0 112.5 3966.2 -1055.5 108.0 1.6
11.9
MWD 11570.00 12.40 296.40 N63.6 W 33 11563.80 169.22 N
87.42 W 145.66 169.88 300.97 4.01 3.94 3.64 -4.1
15.0 112.5 3972.9 -1087.8 108.6 3.9
14.5
P-Bit 11624.00 14.03 296.40 N63.6 W 54 11616.37 181.56 N
92.91 W 156.72 182.19 300.66 3.02 3.02 0.00 -3.8
15.1 112.5 3985.2 -1140.4 109.5 3.0
15.7

into Columns.

Thanks for you help,

Jack

"Jack" <j...@webfoxmail.comwrote in message

news:72**********************************@microsof t.com...
Hello,
How do I do that?
Thanks,
Jack
"Chris Dunaway" <dunaw...@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>Thanks for the help, but I need to return just the Item with no Blank
string.
I'm not sure what you mean by this. The Split method does not return
any spaces. If you happen to have more than one consecutive space in
the original string, you could use the alternate overload and specify
the RemoveEmptyEntries option.
Please explain further what problem you are having with String.Split
Chris- Hide quoted text -

- Show quoted text -
Hi,
here is simple program that do this stuff. No check whether number of
columns is permanent from line to line. Elements in line are separated
with space(s) or tabs.
' CODE STARTS HERE
Imports System.Collections.Generic
Imports System.IO
Imports System.Text

Module Module1
Const Space As Char = Chr(32)
Const Tab As Char = Chr(9)

Sub Main()

Dim Elements As New List(Of String)
Dim LineNum As Integer = 0
Dim ColNum As Integer = 0
Dim f As New StreamReader("c:\work\dotnet\cols1.txt")
Dim ColNumTest As Integer = 0

While Not f.EndOfStream
Dim str() As Char = (f.ReadLine()).ToCharArray

ColNum = 0
Dim elem As String = String.Empty
For Each c As Char In str
If c = Space Or c = Tab Then
If elem <String.Empty Then
Elements.Add(elem)
ColNum += 1
elem = String.Empty
End If
Else
elem &= c
End If
Next

' line completed here

LineNum += 1
End While

f.Close()
If LineNum 1 AndAlso ColNum 1 Then

Dim column As New List(Of String)
For col As Integer = 0 To ColNum - 1
Console.Write(String.Format("Column No.{0} ", col +
1))
For line As Integer = 0 To LineNum - 1
column.Add(Elements(col + line * ColNum))
Console.Write(Elements(col + line * ColNum) & "
")
Next
Console.WriteLine()
' at this point current column is completed
'and you can do with your column what you want
Next
End If

Console.ReadLine()

End Sub

End Module
' CODE END HERE

RESULT:
Column No.1 MWD MWD MWD MWD MWD MWD
Column No.2 11409.00 11441.00 11473.00 11505.00 11537.00
11570.00
Column No.3 3.00 6.10 8.60 10.60 11.10 12.40
Column No.4 298.30 293.80 294.00 294.90 295.20 296.40
Column No.5 N61.7 N66.2 N66.0 N65.1 N64.8 N63.6
Column No.6 W W W W W W
Column No.7 31 32 32 32 32 33
Column No.8 11404.89 11436.78 11468.52 11500.07 11531.49
11563.80
Column No.9 144.51 147.05 151.14 156.48 162.50 169.22
Column No.10 N N N N N N
Column No.11 76.99 78.07 79.73 81.94 84.49 87.42
Column No.12 W W W W W W
Column No.13 123.27 125.56 129.30 134.16 139.61 145.66
Column No.14 145.33 147.85 151.91 157.20 163.19 169.88
Column No.15 301.99 301.87 301.66 301.42 301.18 300.97
Column No.16 5.08 9.74 7.81 6.27 1.57 4.01
Column No.17 1.81 9.69 7.81 6.25 1.56 3.94
Column No.18 -101.8 -14.06 0.62 2.81 0.94 3.64
Column No.19 -5.8 -5.3 -4.9 -4.6 -4.4 -4.1
Column No.20 15.4 15.4 15.2 15.1 15.0 15.0
Column No.21 112.5 112.5 112.5 112.5 112.5 112.5
Column No.22 3948.2 3950.7 3954.8 3960.1 3966.2 3972.9
Column No.23 -928.9 -960.8 -992.5 -1024.1 -1055.5 -1087.8
Column No.24 105.9 106.4 106.9 107.5 108.0 108.6
Column No.25 1.8 9.7 7.8 6.2 1.6 3.9
Column No.26 4.0 11.3 12.8 14.0 11.9 14.5

HTH
Kind regards
Serge
http://www.sergejusz.com

May 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Newton | last post by:
I want to use STL's sort algorithm to sort a string vector. Some of the strings are fairly long (300 to 400 chars) and the vector isn't small (5,000 to 10,000 elements). Naturally, sorting time...
2
by: Sebek | last post by:
Hello, I'm transforming a XML document in XHTML but I have problems using sub-strings, it will be clearer with an exemple: What I have: <form...
41
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
9
by: Sreejith S S Nair | last post by:
hi there, I have a panel control which contain more than 10 label controls. these label controls are added dynamically by user. In this application user can slit a control into not less than...
14
by: Nick Z. | last post by:
I have a file that I want to read a UTF-16 unicode string from. What is the easiest way to accomplish that? Thanks in advance, Nick Z.
2
by: Jon | last post by:
Hello all, I was wondering if someone could give me a quick bit of help! I have a string such as the below name$id|type,name$id|type,name$id|type that I split on the , to create
11
by: s99999999s2003 | last post by:
hi i have a file with xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx:yyy
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.