473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,00 0

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 19215
dim criteria as string = "(frederico)|(F GB)"
dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion & ",?)|(,?"
& criterion & "$)"
dim regExp as new regEx(pattern)
dim match as match
dim yourString as string = "000,federico,0 0,439827HGH,123 3,FGB,0000,00,0 00"
for each match in regExp.Matches( yourString)
console.writeli ne(match.value)
next

or something therebouts.

hth,

steve
"Federico G. Babelis" <fe******@gazum .com> wrote in message
news:uC******** ******@TK2MSFTN GP10.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,00 0
|
| 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.supe rnews.com...
dim criteria as string = "(frederico)|(F GB)"
dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion & ",?)|(,?" & criterion & "$)"
dim regExp as new regEx(pattern)
dim match as match
dim yourString as string = "000,federico,0 0,439827HGH,123 3,FGB,0000,00,0 00" for each match in regExp.Matches( yourString)
console.writeli ne(match.value)
next

or something therebouts.

hth,

steve
"Federico G. Babelis" <fe******@gazum .com> wrote in message
news:uC******** ******@TK2MSFTN GP10.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,00 0
|
| 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.Reg ularExpressions

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

Private Sub printMatches(By Val thingsToFind As String(), ByVal
stringToSearch As String)
Dim criteria As String = "(" & Join(thingsToFi nd, ")|(") & ")"
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.WriteLi ne(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******** ******@TK2MSFTN GP10.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,00 0

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(someCvsFi le, vbcrlf)
dim record as string
dim rexExp as new regex(",(?=(?:[^']*',[^']*',)*(?![^']*',))")
for each record in records
dim columns() as string = regExp.split(re cord);
dim column as string
for each column in columns
console.writeli ne(column)
next
next
"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.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******** ******@TK2MSFTN GP10.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,00 0
| >
| > 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.Reg ularExpressions
Dim SplitAddress() As String
Dim strAddressEleme nt As String
Dim mAddress As String

SplitAddress = Regex.Split(mAd dress, ",")

For Each strAddressEleme nt In SplitAddress
mDemographics += strAddressEleme nt.Trim & ControlChars.Cr Lf
Next
Best wishes

Paul Bromley

"Federico G. Babelis" <fe******@gazum .com> wrote in message
news:uC******** ******@TK2MSFTN GP10.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,00 0

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.supe rnews.com...
dim criteria as string = "(frederico)|(F GB)"
dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion & ",?)|(,?" & criterion & "$)"
dim regExp as new regEx(pattern)
dim match as match
dim yourString as string = "000,federico,0 0,439827HGH,123 3,FGB,0000,00,0 00" for each match in regExp.Matches( yourString)
console.writeli ne(match.value)
next

or something therebouts.

hth,

steve
"Federico G. Babelis" <fe******@gazum .com> wrote in message
news:uC******** ******@TK2MSFTN GP10.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,00 0
|
| 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**********@p lanet.nl> wrote in message
news:OX******** ******@tk2msftn gp13.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.supe rnews.com...
| > dim criteria as string = "(frederico)|(F GB)"
| > dim pattern as string = "(^" & criteria & ",?)|(,?" & criterion &
| ",?)|(,?"
| > & criterion & "$)"
| > dim regExp as new regEx(pattern)
| > dim match as match
| > dim yourString as string =
| "000,federico,0 0,439827HGH,123 3,FGB,0000,00,0 00"
| > for each match in regExp.Matches( yourString)
| > console.writeli ne(match.value)
| > next
| >
| > or something therebouts.
| >
| > hth,
| >
| > steve
| >
| >
| > "Federico G. Babelis" <fe******@gazum .com> wrote in message
| > news:uC******** ******@TK2MSFTN GP10.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,00 0
| > |
| > | 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

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

Similar topics

1
5259
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
11691
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 need to find out if this string contains the words "Not found". Is there a C# function for it? or perhaps I could use wildcards? Or can I use StringBuilder for this?
2
3308
by: Ryan Learns Sharp | last post by:
Is there any convenient way to handle this? Thank you!
0
1257
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 these are found in the InitialiseComponent method and are therefore literals on a line of code preceeded with "Me.". So, is there a regular expression that will find all literals NOT on a line preceeded with "Me."? Thanks :/
6
2781
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
12836
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 position here ($10) but the text I extract is sometimes in a different position in the header so I need to search for preceding text "LINE:" and then extract the next string, which is the info I'm interested in. So - using awk or sed (or perl if need...
4
5413
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
14980
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
2236
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
3799
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
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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 we have to send another system
3
2147
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.