473,230 Members | 1,930 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,230 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 3996
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 = " ",...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.