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

Find a String in VB.NET

Hi,

I need to extract a string from another string separated by "," like a .csv
file.
for example I have this string:

String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000

and from that string i need to extract string "federico" and string "FGB"
and separate then into another 2 strings:

String2 = "federico"
String3 = "FGB"

How this could be done in Visual Basic .NET ????

Thanks and best regards,
Federico
Nov 20 '05 #1
10 19189
dim criteria as string = "(frederico)|(FGB)"
dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion & ",?)|(,?"
& criterion & "$)"
dim regExp as new regEx(pattern)
dim match as match
dim yourString as string = "000,federico,00,439827HGH,1233,FGB,0000,00,00 0"
for each match in regExp.Matches(yourString)
console.writeline(match.value)
next

or something therebouts.

hth,

steve
"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
| Hi,
|
| I need to extract a string from another string separated by "," like a
..csv
| file.
| for example I have this string:
|
| String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000
|
| and from that string i need to extract string "federico" and string "FGB"
| and separate then into another 2 strings:
|
| String2 = "federico"
| String3 = "FGB"
|
| How this could be done in Visual Basic .NET ????
|
| Thanks and best regards,
| Federico
|
|
Nov 20 '05 #2
Steve:

Thanks but, maybe I explain this in the wrong way, because the strings
always will be different and will don't know its value at any time, the only
thing that will know is the position regarding the "," character.

any idea ?

Thanks again...
Federico

"steve" <a@b.com> wrote in message
news:10*************@corp.supernews.com...
dim criteria as string = "(frederico)|(FGB)"
dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion & ",?)|(,?" & criterion & "$)"
dim regExp as new regEx(pattern)
dim match as match
dim yourString as string = "000,federico,00,439827HGH,1233,FGB,0000,00,00 0" for each match in regExp.Matches(yourString)
console.writeline(match.value)
next

or something therebouts.

hth,

steve
"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
| Hi,
|
| I need to extract a string from another string separated by "," like a
.csv
| file.
| for example I have this string:
|
| String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000
|
| and from that string i need to extract string "federico" and string "FGB" | and separate then into another 2 strings:
|
| String2 = "federico"
| String3 = "FGB"
|
| How this could be done in Visual Basic .NET ????
|
| Thanks and best regards,
| Federico
|
|

Nov 20 '05 #3
just make variable what needs to be variable...

====================

Imports System.Text.RegularExpressions

Public Sub Main()
Dim thingsToMatch() As String = {"federico", "FGB"}
printMatches(thingsToMatch,
"000,federico,00,439827HGH,1233,FGB,0000,00,00 0")
End Sub

Private Sub printMatches(ByVal thingsToFind As String(), ByVal
stringToSearch As String)
Dim criteria As String = "(" & Join(thingsToFind, ")|(") & ")"
Dim pattern As String = "(^" & criteria & "(?=,?))|((?=,?)" & criteria &
"(?=,?))|((?=,?)" & criteria & "$)"
Dim regExp As New Regex(pattern)
Dim match As Match
For Each match In regExp.Matches(stringToSearch)
Console.WriteLine(match.Value)
Next
End Sub

this is just a quick/maintainable way of parsing your string...make it what
you want...if you don't like regular expressions, there's always
string.indexOf()

hth,

steve
Nov 20 '05 #4
First of all, you souldn't post the same question in multiple groups.

here is the answer you are looking for

Dim MyArray() As String = string1.Split(",")
String2 = MyArray(1)
String3 = MyArray(5)

"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
Hi,

I need to extract a string from another string separated by "," like a
.csv
file.
for example I have this string:

String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000

and from that string i need to extract string "federico" and string "FGB"
and separate then into another 2 strings:

String2 = "federico"
String3 = "FGB"

How this could be done in Visual Basic .NET ????

Thanks and best regards,
Federico

Nov 20 '05 #5
he's searching for values w/n a string...right? if so, he doesn't know in
which array element a match will occur. second, if this is the case, this
method leaves a lot to be desired as far as finding the position w/n the
source string the match(es) occur.

now if he actually is parsing a cvs file then a more *refined* split is
called for since the value itself may contain a comma...

' for example...else, better to read/process file a line at a time
' to avoid memory problems w/ large files
dim records() as string = split(someCvsFile, vbcrlf)
dim record as string
dim rexExp as new regex(",(?=(?:[^']*',[^']*',)*(?![^']*',))")
for each record in records
dim columns() as string = regExp.split(record);
dim column as string
for each column in columns
console.writeline(column)
next
next
"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...
| First of all, you souldn't post the same question in multiple groups.
|
| here is the answer you are looking for
|
| Dim MyArray() As String = string1.Split(",")
| String2 = MyArray(1)
| String3 = MyArray(5)
|
| "Federico G. Babelis" <fe******@gazum.com> wrote in message
| news:uC**************@TK2MSFTNGP10.phx.gbl...
| > Hi,
| >
| > I need to extract a string from another string separated by "," like a
| > .csv
| > file.
| > for example I have this string:
| >
| > String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000
| >
| > and from that string i need to extract string "federico" and string
"FGB"
| > and separate then into another 2 strings:
| >
| > String2 = "federico"
| > String3 = "FGB"
| >
| > How this could be done in Visual Basic .NET ????
| >
| > Thanks and best regards,
| > Federico
| >
| >
|
|
Nov 20 '05 #6
Take a look at Regex - you ill find a lot
of very useful techniques that you can apply to many things. It is very easy
then to do the split that you ar aiming to achived based on the comma
delimiter. There are a number of very good sites on Regex if you look at
Google. Start with a couple of simple Regexes.

I used something like below to convert an address delimited by commas into
an address block. Knowing my coding, this may not be the most elegant way -
but ot works for me!

Imports System.Text.RegularExpressions
Dim SplitAddress() As String
Dim strAddressElement As String
Dim mAddress As String

SplitAddress = Regex.Split(mAddress, ",")

For Each strAddressElement In SplitAddress
mDemographics += strAddressElement.Trim & ControlChars.CrLf
Next
Best wishes

Paul Bromley

"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
Hi,

I need to extract a string from another string separated by "," like a ..csv file.
for example I have this string:

String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000

and from that string i need to extract string "federico" and string "FGB"
and separate then into another 2 strings:

String2 = "federico"
String3 = "FGB"

How this could be done in Visual Basic .NET ????

Thanks and best regards,
Federico

Nov 20 '05 #7
Hi Steve

Have a look at the split method

http://msdn.microsoft.com/library/de...splittopic.asp

That is in my opinion made for your problem

I hope this helps?

Cor

"steve" <a@b.com> schreef in bericht
news:10*************@corp.supernews.com...
dim criteria as string = "(frederico)|(FGB)"
dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion & ",?)|(,?" & criterion & "$)"
dim regExp as new regEx(pattern)
dim match as match
dim yourString as string = "000,federico,00,439827HGH,1233,FGB,0000,00,00 0" for each match in regExp.Matches(yourString)
console.writeline(match.value)
next

or something therebouts.

hth,

steve
"Federico G. Babelis" <fe******@gazum.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
| Hi,
|
| I need to extract a string from another string separated by "," like a
.csv
| file.
| for example I have this string:
|
| String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000
|
| and from that string i need to extract string "federico" and string "FGB" | and separate then into another 2 strings:
|
| String2 = "federico"
| String3 = "FGB"
|
| How this could be done in Visual Basic .NET ????
|
| Thanks and best regards,
| Federico
|
|

Nov 20 '05 #8
i gave a split method example too...look in this thread. also, i'm not the
op. i gave two examples b/c of the vagueness in the description of what the
op is trying to acheive...one being a delimited string search returning
matches...the other treating the input as a cvs, tick (') encapsulted, comma
separated stream of data. hopefully, one of the two is exactly what's
needed...else, there is enough there for the op to work with.

thanks for your thoughts though.

post you later, cor.

steve
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OX**************@tk2msftngp13.phx.gbl...
| Hi Steve
|
| Have a look at the split method
|
|
http://msdn.microsoft.com/library/de...splittopic.asp
|
| That is in my opinion made for your problem
|
| I hope this helps?
|
| Cor
|
| "steve" <a@b.com> schreef in bericht
| news:10*************@corp.supernews.com...
| > dim criteria as string = "(frederico)|(FGB)"
| > dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion &
| ",?)|(,?"
| > & criterion & "$)"
| > dim regExp as new regEx(pattern)
| > dim match as match
| > dim yourString as string =
| "000,federico,00,439827HGH,1233,FGB,0000,00,00 0"
| > for each match in regExp.Matches(yourString)
| > console.writeline(match.value)
| > next
| >
| > or something therebouts.
| >
| > hth,
| >
| > steve
| >
| >
| > "Federico G. Babelis" <fe******@gazum.com> wrote in message
| > news:uC**************@TK2MSFTNGP10.phx.gbl...
| > | Hi,
| > |
| > | I need to extract a string from another string separated by "," like a
| > .csv
| > | file.
| > | for example I have this string:
| > |
| > | String1 = 000,federico,00,439827HGH,1233,FGB,0000,00,000
| > |
| > | and from that string i need to extract string "federico" and string
| "FGB"
| > | and separate then into another 2 strings:
| > |
| > | String2 = "federico"
| > | String3 = "FGB"
| > |
| > | How this could be done in Visual Basic .NET ????
| > |
| > | Thanks and best regards,
| > | Federico
| > |
| > |
| >
| >
|
|
Nov 20 '05 #9
Hi Steve,

Normaly I do not echo, I saw it when I had sended the message that there was
more, however I did not correct that (although I was in doubt) I thought it
is even more confusing for the OP, however it was an accident. It is not my
normal way of behave.

Sorry

Cor
Nov 20 '05 #10
cor,

i've been in this ng for quite a while. you are held in my highest esteem
and have little to worry about regarding how i view your responses. no
appology needed as i figured that was the case. i responded to your post
just to let you know there was an example available in the thread...in case
you wanted to look at it.

we all have our moments ;^) (mine are more frequent than most)

post you later,

me
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
| Hi Steve,
|
| Normaly I do not echo, I saw it when I had sended the message that there
was
| more, however I did not correct that (although I was in doubt) I thought
it
| is even more confusing for the OP, however it was an accident. It is not
my
| normal way of behave.
|
| Sorry
|
| Cor
|
|
Nov 20 '05 #11

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

Similar topics

1
by: brainjk | last post by:
I want to find if a data string is somewhere in a table but i dont know the table of the database or the field. Who can i search anywhere? Thanks Brainjk
3
by: Peter Afonin | last post by:
Hello: In VB I was using InStr function to determice whether some string exists within another string. How would I do it in C#? For instance, I have a long string created by StringBuilder. I...
2
by: Ryan Learns Sharp | last post by:
Is there any convenient way to handle this? Thank you!
0
by: Robin Tucker | last post by:
I'm localizing and need to find all string literals in my source code. I don't want to find any of the literals that will end up in resources however. As I don't use the "Me" keyword, I know...
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
2
by: Bryan_Cockrell | last post by:
Hi World, I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent. I'm using a specific string...
4
by: xdevel | last post by:
Hi, if I want to read the string functions source code (i.e. strcpy, strtok etc.) where can I find them?
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
3
by: shapper | last post by:
Hello, I have two arrays of strings, s1 and s2: s1 = "london, lisbon, paris, newyork" s2 = "lisbon, yellow, France" s2 will have only one item included in s1.
5
by: fminervino | last post by:
Hi friends !! I'm neophite about python, my target is to create a programa that find a specific string in text file. How can do it? Thanks fel
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
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 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.