473,382 Members | 1,387 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,382 software developers and data experts.

split() question

KC
Can I do a split() on a string where the delimiter is one or more space
characters? I have a string with spaces between the numbers but I don't know
how many. You can do this easy in Perl, but VB.net ain't Perl...

Ken
Nov 20 '05 #1
5 1561
"KC" <yo*@dontneed.this> skrev i en meddelelse
news:uI*************@TK2MSFTNGP11.phx.gbl...
Can I do a split() on a string where the delimiter is one or more space
characters? I have a string with spaces between the numbers but I don't know how many. You can do this easy in Perl, but VB.net ain't Perl...

Ken


You have to do like this, atleast I don't know any other way

dim str as string = "234 23 42 234 234 234"
str = str.split(" ")
dim moreSpaces as integer = str.indexof(" ")
while morespaces <> -1
str = str.split(" ")
moreSpaces = str.indexof(" ")
end while
Nov 20 '05 #2
Use Regular Expressions.

"Richard" <s@b.k> wrote in message
news:ea*************@TK2MSFTNGP12.phx.gbl...
"KC" <yo*@dontneed.this> skrev i en meddelelse
news:uI*************@TK2MSFTNGP11.phx.gbl...
Can I do a split() on a string where the delimiter is one or more space
characters? I have a string with spaces between the numbers but I don't

know
how many. You can do this easy in Perl, but VB.net ain't Perl...

Ken


You have to do like this, atleast I don't know any other way

dim str as string = "234 23 42 234 234 234"
str = str.split(" ")
dim moreSpaces as integer = str.indexof(" ")
while morespaces <> -1
str = str.split(" ")
moreSpaces = str.indexof(" ")
end while

Nov 20 '05 #3
> dim str as string = "234 23 42 234 234 234"
str = str.split(" ")
dim moreSpaces as integer = str.indexof(" ")
while morespaces <> -1
str = str.split(" ")
moreSpaces = str.indexof(" ")
end while


LOL
My bad I thought i was another operation,
It will work with split, but there might be some empty strings in the array
you are getting
Nov 20 '05 #4
My bad, it will work
Nov 20 '05 #5
Ken,
As Juan suggested, you can use RegEx.Split...

There are three Split functions in .NET:

Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.

Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.

Hope this helps
Jay
"KC" <yo*@dontneed.this> wrote in message
news:uI*************@TK2MSFTNGP11.phx.gbl...
Can I do a split() on a string where the delimiter is one or more space
characters? I have a string with spaces between the numbers but I don't know how many. You can do this easy in Perl, but VB.net ain't Perl...

Ken

Nov 20 '05 #6

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

Similar topics

3
by: alexk | last post by:
I've a simple question. Why the following: words = "123#@$#$@^% wordB#@$".split('~`!@#$%^&*()_+-={},./') doesn't work? The length of the result vector is 1. I'm using ActivePython 2.4 Alex
2
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces,...
3
by: rxl124 | last post by:
Hi, room Beginner of learning perl here!! I have question to all, I have below file name datebook.master which contains only 2 lines Mike wolf:12/3/44:144 park ave, paramus: 44000 Sarah kim:...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
3
by: John Salerno | last post by:
This is an example in the book I'm reading: string fullName = " Edward C Koop "; fullName = fullName.Trim(); string names = fullName.Split(' '); string firstName = names; //...
4
by: Michele Petrazzo | last post by:
Hello ng, I don't understand why split (string split) doesn't work with the same method if I can't pass values or if I pass a whitespace value: >>> "".split() >>> "".split(" ") But into...
7
by: Matthias Winterland | last post by:
Hi, I have a simple question. When I read in a string like: a='1,2,3,4,5 6 7,3,4', can I get the list l= with a single split-call? Thx, Matthias
9
by: dtex23 | last post by:
Good afternoon all, Question about list assignment in perl... Given a piece of code that looks kinda like this for parsing some '|' delimited input text lines : ($var1, $var2, $var3) =...
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 = " ",...
1
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...
0
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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$) { } ...
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.