473,405 Members | 2,176 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,405 software developers and data experts.

issue with split function in vb.net

I am trying to use the split function to bread up lines in a file I am
reading from. Some lines are working just fine, but a couple of the lines
don't split up the way I would have thought.

Here's part of the code.
Dim strDelim As String = "*~"
Dim delimiter As Char() = strDelim.ToCharArray
Dim split As String() = Nothing
Dim fieldCount As Integer
Dim s As String

split = line.Split(delimiter, line.Split.GetUpperBound(0))
fieldCount = 0
For Each s In split
Dim y As String = s
If y <> "" Then
fieldCount = fieldCount + 1
End If
Next s
strAddress = split.GetValue(fieldCount - 1)

Here's a sample line that works
N3*SU*1685 N MAIN ST~
Here's a line that doesn't work
N3*ST*MAP*24000 Honda Pkwy~
The line that doesn't work breaks after the N3, but it includes everything
else in the second split.
The line that works splits everything fine.
Let me know what I can change, or what I am doing wrong.
--
Thanks
Jul 21 '05 #1
5 4011
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are unable to split some of your
string lines. If there is any misunderstanding, please feel free to let me
know.

I think the part "line.Split.GetUpperBound(0)" is not necessary in the
code, because the Split method will split according to all delimiters
without specifying the count. So I changed the code to the following. It
works fine on my machine.

Dim strDelim As String = "*~"
Dim delimiter As Char() = strDelim.ToCharArray
Dim split As String() = Nothing
Dim fieldCount As Integer
Dim s As String

split = line.Split(delimiter)
fieldCount = 0
For Each s In split
Dim y As String = s
If y <> "" Then
fieldCount = fieldCount + 1
End If
Next s
Dim strAddress As Object = split.GetValue(fieldCount - 1)

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
Yes you are correct. If you look at the 2 lines I gave as an example. The
first one
N3*SU*1685 N MAIN ST~
splits at the * just fine, giving me 3 fields.
The second one
N3*ST*MAP*24000 Honda Pkwy~
only splits after the N3 giving me only 2 fields and not the 4 I would expect.

--
Thanks
"Kevin Yu [MSFT]" wrote:
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are unable to split some of your
string lines. If there is any misunderstanding, please feel free to let me
know.

I think the part "line.Split.GetUpperBound(0)" is not necessary in the
code, because the Split method will split according to all delimiters
without specifying the count. So I changed the code to the following. It
works fine on my machine.

Dim strDelim As String = "*~"
Dim delimiter As Char() = strDelim.ToCharArray
Dim split As String() = Nothing
Dim fieldCount As Integer
Dim s As String

split = line.Split(delimiter)
fieldCount = 0
For Each s In split
Dim y As String = s
If y <> "" Then
fieldCount = fieldCount + 1
End If
Next s
Dim strAddress As Object = split.GetValue(fieldCount - 1)

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #3
You're welcome.

After modifying the code, it works fine on my machine with both lines.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4
It's working with your suggestion. Thank you so much. I have been banging
my head against the wall on this one for a while.
--
Thanks
"Kevin Yu [MSFT]" wrote:
You're welcome.

After modifying the code, it works fine on my machine with both lines.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #5
Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #6

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

Similar topics

0
by: Sucpraran | last post by:
We are using Cookies in our application to track user session. It works 95% but fails in occations. We could not find any pattern for this. Below is the code to Set and Get cookies. In the...
6
by: Mike | last post by:
I have a function that is called when the user clicks the submit button, during this function i also set a varaible to "Y" due to that this function does a post back to the page then redirects....
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: NewToThis | last post by:
I am trying to use the split function to bread up lines in a file I am reading from. Some lines are working just fine, but a couple of the lines don't split up the way I would have thought. ...
2
by: Louis | last post by:
Hope somebody can tell me why this happens to filehandles... I am playing with perl packages, and I had all functions in one file. Now I want to split them into different files using package. ...
6
by: daveyand | last post by:
Hey Guys, I've stumped. I created a function that does various things to select boxes. Namely Get All selected indexes, populate array with these values
1
by: flutetones | last post by:
http://67.189.52.24/~metafusionserver/public_html/training.php Here is a link to my server. I have an issue that doen't make sense. What's hapening is this . . . What's going right . . .
0
by: kamboj.shalabh | last post by:
Hi to all, Well, I am working on dotnet 2005 with crystal reports 10 and backend as sql server. I am facing a problem while loading a report. Actually the issue is, when I load report it takes...
1
by: John | last post by:
Hi I have written a Split function which in turn calls the standard string split function. Code is below; Function Split1(ByVal Expression As String, Optional ByVal Delimiter As String = " ",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.