473,508 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

load words in a string into an array?

J
anybody know a vb.net command to populate an array with each word in a
string? for example " hi how are you"

array(0) = hi
array(1) = how
array(2) = are
array(3) = you

i know i could loop though and search for spaces and build it that way...but
a built in command would be great.

any thoughts?
Nov 20 '05 #1
4 12659
J
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.

Seeing as you want a single space I would recommend String.Split, something
like:
Dim input As String = " hi how are you"
Dim array As String()
array = input.Split(" "c)
For Each word As String in words
Debug.WriteLine(word)
Next

Note the trailing or leading spaces will cause an empty string to be added
to the returned array. You can use String.Trim first to remove trailing or
leading spaces if needed...

Hope this helps
Jay
"J" <ja******@comcast.net> wrote in message
news:ip********************@comcast.com...
anybody know a vb.net command to populate an array with each word in a
string? for example " hi how are you"

array(0) = hi
array(1) = how
array(2) = are
array(3) = you

i know i could loop though and search for spaces and build it that way...but a built in command would be great.

any thoughts?

Nov 20 '05 #2
On 2004-01-08, J <ja******@comcast.net> wrote:
anybody know a vb.net command to populate an array with each word in a
string? for example " hi how are you"

array(0) = hi
array(1) = how
array(2) = are
array(3) = you

i know i could loop though and search for spaces and build it that way...but
a built in command would be great.

any thoughts?


Dim words() As String = "hi how are you".Split(" ".ToCharArray())

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #3
J
awesome! thanks a lot

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
J
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.

Seeing as you want a single space I would recommend String.Split, something like:
Dim input As String = " hi how are you"
Dim array As String()
array = input.Split(" "c)
For Each word As String in words
Debug.WriteLine(word)
Next

Note the trailing or leading spaces will cause an empty string to be added
to the returned array. You can use String.Trim first to remove trailing or
leading spaces if needed...

Hope this helps
Jay
"J" <ja******@comcast.net> wrote in message
news:ip********************@comcast.com...
anybody know a vb.net command to populate an array with each word in a
string? for example " hi how are you"

array(0) = hi
array(1) = how
array(2) = are
array(3) = you

i know i could loop though and search for spaces and build it that

way...but
a built in command would be great.

any thoughts?


Nov 20 '05 #4
* "J" <ja******@comcast.net> scripsit:
anybody know a vb.net command to populate an array with each word in a
string? for example " hi how are you"

array(0) = hi
array(1) = how
array(2) = are
array(3) = you

i know i could loop though and search for spaces and build it that way...but
a built in command would be great.


Have a look at 'Strings.Split' or the string's 'Split' method.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

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

Similar topics

6
10839
by: Bimo Remus | last post by:
Hi, I am currently taking a C++ class and am having problems with a homework assignment. My problem is that I need to pull the first and last words out of of a character string array which is in...
8
2182
by: Rick | last post by:
I have a program that reads from a file. In the file are a series of words. I read in all the words into a string array, find the average length, count the number of words, display the longest...
7
43561
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
7
3168
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
3
2947
by: Csaba Gabor | last post by:
I'm comparing the text of (snippets of) web pages which I expect to be quite different or quite similar. In the case where they are similar, I would like to display the more recent one and say...
8
4976
by: shapper | last post by:
Hello, I have a string which holds a text. Is it possible to create a substring which uses the first N words of that string? Thanks, Miguel
20
5100
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want...
6
1539
by: Bint | last post by:
I have an array whose elements I'm accessing, like array, array, etc. However, the data is meant to be 16-bit words, not bytes. I'm getting byte values right now. Is there any way I can tell php...
8
3239
by: amphetaman | last post by:
Is there a safe (unlikely to cause overflows or segfaults) way to load a text file into a char ** array? I thought of using getline, but it needs a fixed-length string, and I don't know how many...
0
7226
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
7125
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
7388
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...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
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
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.