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

how do I find position of character in string

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
9 26132
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
Use the string.split method

Jul 21 '05 #3
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Looks Like Trent | last post by:
Find a character in a string, at a specified position. How do you do this? Any help will be appreciated....
2
by: Faz | last post by:
I am trying to extract text before a certain character appears in a string. This character is the letter "C". Here is some sample data - the field is called REFERENCE_2: REFERENCE_2...
4
by: Neil Robbins | last post by:
Could anyone suggest a way in which I could find the position of the cursor within a textbox. I want to evaluate every keypress made within the textbox in order to validate it but in order to do...
6
by: KJ | last post by:
How can you look for a character in a certain position with VB.Net and if the string length is less than the position have it return and empty string instead of an error? Substring returnns an...
17
by: PaulThomas | last post by:
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...
3
by: magix | last post by:
Dear Guru, I have been thinking hard on how to token based on demiliter after certain position. Example, I have list of possible string below, and the the delimiter is "1" with the rules below...
3
by: magix | last post by:
How can I search for occurance of a character in certain position of a string I checked function strchr, but doesn't option to specify position. Thanks. Regards, Magix
7
kireytir
by: kireytir | last post by:
hi all, this is my code (in interrupt function) for finding character in string (data). Ekle_text.Text += data; string veri = Ekle_text.Text; int found = veri.IndexOf("x"); if (found !=...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.