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

Parse a String and get unique values

Hi,

I'm looking for ideas for the most efficient way to accomplish this. I have a string representing names a person goes by.

"John Myers Joe John Myers"

And I need to parse it in such a way that I end up with an array of UNIQUE strings that appear in the original string (In no particular order)

arr(0) = "John"
arr(1) = "Myers"
arr(2) = "Joe"

One way I can think of is to use a hashtable and add the words like they were keys, then just iterate through the end result, The results should be unique, but I'm not sure that would be the best method for performance.

Thanks for any ideas!
--Michael
Nov 21 '05 #1
2 2749
Here is an example from the VS2003 help files for string
parsing - Note how you can have several delimeters listed -
you need to have delimeters in your string.

Sub strSplit()
'4 delimeters here, a space, comma, period, colon
Dim delimStr As String = " ,.:"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim words As String = "one two,three:four."
Dim split As String() = Nothing
Console.WriteLine("The delimiters are -{0}-", delimStr)
Dim x As Integer
For x = 1 To 5
split = words.Split(delimiter, x)
Console.WriteLine(ControlChars.Cr + "count =
{0,2} ..............", x)
Dim s As String
For Each s In split
Console.WriteLine("-{0}-", s)
Next s
Next x
End Sub

-----Original Message-----
Hi,

I'm looking for ideas for the most efficient way to accomplish this. I have a string representing names a
person goes by.
"John Myers Joe John Myers"

And I need to parse it in such a way that I end up with an array of UNIQUE strings that appear in the original
string (In no particular order)
arr(0) = "John"
arr(1) = "Myers"
arr(2) = "Joe"

One way I can think of is to use a hashtable and add the words like they were keys, then just iterate through the
end result, The results should be unique, but I'm not sure
that would be the best method for performance.
Thanks for any ideas!
--Michael
.

Nov 21 '05 #2
something like:

(?=(\b\w+\b)|^)([^\1]*)\1+

could be used in a regex replace on the original string to give you unique
words...replacing w/ $2. from there you could just do a regex split on \b
(word boundry). viola, there's your unique array.

hth,

steve
"Raterus" <mo*********@suretar.reverse> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Hi,

I'm looking for ideas for the most efficient way to accomplish this. I have
a string representing names a person goes by.

"John Myers Joe John Myers"

And I need to parse it in such a way that I end up with an array of UNIQUE
strings that appear in the original string (In no particular order)

arr(0) = "John"
arr(1) = "Myers"
arr(2) = "Joe"

One way I can think of is to use a hashtable and add the words like they
were keys, then just iterate through the end result, The results should be
unique, but I'm not sure that would be the best method for performance.

Thanks for any ideas!
--Michael
Nov 21 '05 #3

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

Similar topics

2
by: N | last post by:
Hi, I would like to parse out each value that is seperated by a comma in a field and use that value to join to another table. What would be the easiest way to do so without having to write a...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
24
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.