how do I find position of character in string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.ToString());

Console.ReadLine();
 
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 said:
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.ToString());

Console.ReadLine();

Chris Dunaway said:
Use the string.split method
 
Paul, if the source data doesn't have quotes, the string array would also not
contain quotes. So, no need of replacing anything.

PaulThomas said:
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 said:
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.ToString());

Console.ReadLine();

Chris Dunaway said:
Use the string.split method
 
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
 
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
 
Back
Top