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 5 4008
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."
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."
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."
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."
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." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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....
|
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......
|
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.
...
|
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.
...
|
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
|
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 . . .
|
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...
|
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 = " ",...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |