By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

how do I find position of character in string

P: n/a
I want to "look" through a comma delimited String and "take it apart" by
finding the comma's and then put each "set of characters" into seperate
strings - - - maybe an array, maybe seperate cells in a table -or-
whatever... Can anyone help me locate the commands (samples) that might do
this?
Actually, I want to read a file and use these comma seperated groups of data
to "load" a database and this comma seperated data is the individual data
columns of the database table that needs to be loaded...
Thanks,
Paul

Jul 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Sorry - I am using VB.Net and C#

"PaulThomas" wrote:
I want to "look" through a comma delimited String and "take it apart" by
finding the comma's and then put each "set of characters" into seperate
strings - - - maybe an array, maybe seperate cells in a table -or-
whatever... Can anyone help me locate the commands (samples) that might do
this?
Actually, I want to read a file and use these comma seperated groups of data
to "load" a database and this comma seperated data is the individual data
columns of the database table that needs to be loaded...
Thanks,
Paul

Jul 21 '05 #2

P: n/a
Use the string.split method

Jul 21 '05 #3

P: n/a
pSm
Paul,
Here's a sample in C# - make sure that your data doesn't have the
separator.

string str="A,B C,D,E";
char chSep=',';
string[] arrStr=str.Split(chSep);
for (int i=0;i<arrStr.Length ;i++)
Console.WriteLine(arrStr[i].ToString());

Console.ReadLine();

"Chris Dunaway" wrote:
Use the string.split method

Jul 21 '05 #4

P: n/a
Thanks,
I now have the String.Split working and trying to get the double quotes out
The data (splitting on comma) now produces an array of:
[0] "Name"
[1] ","
[2] "Info1"
[3] ","
[4] "Info2"
I am trying to use s[0].Replace(""","")
but it doesn't like the first string of the three double-quote I am trying
to remove
and it doesn't like the second string of double quotes ie: empty string
I am trying to remove the doublequotes in front and behind the string data
--or-- Am I just being DUMB looking at the data in the debugger and the
quotes only indicate string data and are not really there --no-- I am
putting each string in the array into a table cell (just to 'see' it) and the
quotes are there...
How can I specify the " character as the character to be replaced and How
can I specify an empty string ie: nothing to replace the " -or- I could
replace the " with a space and then use Trim to get rid of the leading and
trailing space...
Thanks again,
Paul
"pSm" wrote:
Paul,
Here's a sample in C# - make sure that your data doesn't have the
separator.

string str="A,B C,D,E";
char chSep=',';
string[] arrStr=str.Split(chSep);
for (int i=0;i<arrStr.Length ;i++)
Console.WriteLine(arrStr[i].ToString());

Console.ReadLine();

"Chris Dunaway" wrote:
Use the string.split method

Jul 21 '05 #5

P: n/a
pSm
Paul, if the source data doesn't have quotes, the string array would also not
contain quotes. So, no need of replacing anything.

"PaulThomas" wrote:
Thanks,
I now have the String.Split working and trying to get the double quotes out
The data (splitting on comma) now produces an array of:
[0] "Name"
[1] ","
[2] "Info1"
[3] ","
[4] "Info2"
I am trying to use s[0].Replace(""","")
but it doesn't like the first string of the three double-quote I am trying
to remove
and it doesn't like the second string of double quotes ie: empty string
I am trying to remove the doublequotes in front and behind the string data
--or-- Am I just being DUMB looking at the data in the debugger and the
quotes only indicate string data and are not really there --no-- I am
putting each string in the array into a table cell (just to 'see' it) and the
quotes are there...
How can I specify the " character as the character to be replaced and How
can I specify an empty string ie: nothing to replace the " -or- I could
replace the " with a space and then use Trim to get rid of the leading and
trailing space...
Thanks again,
Paul
"pSm" wrote:
Paul,
Here's a sample in C# - make sure that your data doesn't have the
separator.

string str="A,B C,D,E";
char chSep=',';
string[] arrStr=str.Split(chSep);
for (int i=0;i<arrStr.Length ;i++)
Console.WriteLine(arrStr[i].ToString());

Console.ReadLine();

"Chris Dunaway" wrote:
Use the string.split method

Jul 21 '05 #6

P: n/a
Paul,

There are more split methods in the System. namespace there is as well the
Regex Split and in the VisualBasic namespace as well a method Split.

You can always have a look if these fit you better.

Cor
Jul 21 '05 #7

P: n/a
The Regex.Split is working great - it's the double quotes I need to get
rid of because the data is enclosed in '' double quotes
Thanks again,
Paul
"Cor Ligthert" wrote:
Paul,

There are more split methods in the System. namespace there is as well the
Regex Split and in the VisualBasic namespace as well a method Split.

You can always have a look if these fit you better.

Cor

Jul 21 '05 #8

P: n/a
WROX publishes a handbook called "C# Text Manipulation" (VB too) that you
might consider adding as a reference.
I don't know if the series is still in print so you may have to go used via
Amazon.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"PaulThomas" <Pa********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
I want to "look" through a comma delimited String and "take it apart" by
finding the comma's and then put each "set of characters" into seperate
strings - - - maybe an array, maybe seperate cells in a table -or-
whatever... Can anyone help me locate the commands (samples) that might
do
this?
Actually, I want to read a file and use these comma seperated groups of
data
to "load" a database and this comma seperated data is the individual data
columns of the database table that needs to be loaded...
Thanks,
Paul

Jul 21 '05 #9

P: n/a
Use the string.Replace method or indexOf
that takes in double quotes

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:uS**************@TK2MSFTNGP10.phx.gbl...
WROX publishes a handbook called "C# Text Manipulation" (VB too) that you
might consider adding as a reference.
I don't know if the series is still in print so you may have to go used via Amazon.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"PaulThomas" <Pa********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
I want to "look" through a comma delimited String and "take it apart" by
finding the comma's and then put each "set of characters" into seperate
strings - - - maybe an array, maybe seperate cells in a table -or-
whatever... Can anyone help me locate the commands (samples) that might do
this?
Actually, I want to read a file and use these comma seperated groups of
data
to "load" a database and this comma seperated data is the individual data columns of the database table that needs to be loaded...
Thanks,
Paul


Aug 16 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.