473,472 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Double Quote and Comma in String

Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to
split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.

Thank you.

*- character "[" and "]" denotes the start and end of string.
Nov 15 '05 #1
7 9567
Hi,

Doesn't the String.Split method with comma char specified as a separator do
the job?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to
split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.

Thank you.

*- character "[" and "]" denotes the start and end of string.


Nov 15 '05 #2
It does the job but notice the last string - "fi,ve". Split method will
split that string into 2. "fi" and "ve".

My point here is to not split the string in between the starting "
charachter and the closing " until it reached a comma.

Another issue is to include the " character itself, like in a string:
string s = "6,\"as\"\"a;s,d\",\"normal string\"";

Typical split will split the string into {"6", "\"as\"\"a;s", "d\"",
"\"normal string\""};
I wish I can split it into {"6", "\"as\"\"a;s,d\"", "\"normal string\""}

I hope you can see my point.

Please help.

p/s: refer to MSSQL DTS Import/Export Wizard. It does the job so well.
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2*****************@TK2MSFTNGP11.phx.gbl...
Hi,

Doesn't the String.Split method with comma char specified as a separator do the job?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to
split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.

Thank you.

*- character "[" and "]" denotes the start and end of string.

Nov 15 '05 #3
In this case, you probably will have to write your own splitter - and it's
pretty simple. Walk throught the string appending to another string as you
walk. When you encounter a quote, set a flag and continue walking. If you
encounter another quote reset the flag. If you encounter a comma when the
flag is set, add it to the string, if not, complete that string and move
over.

vJ

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to
split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.

Thank you.

*- character "[" and "]" denotes the start and end of string.

Nov 15 '05 #4
Ahmad,

Why don't you use regular expressions?

string expression = "\"1\",\"two\",\" three\", \"fo\"\"ur\", \"fi,ve\"";
MatchCollection col = Regex.Matches(expression,
@"(?:^|\s*\,\s*)(?:""(?<SubString>(?:""""|[^""])*)"")+",RegexOptions.IgnoreC
ase | RegexOptions.IgnorePatternWhitespace);
foreach (System.Text.RegularExpressions.Match match in col)
{
string subString = match.Groups["SubString"].Value;
}

dont forget to use namespace System.Text.RegularExpressions

B.T.W - it doesnt work if the first substring (1) is not surrounded with "
as well...

Picho
"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to
split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.

Thank you.

*- character "[" and "]" denotes the start and end of string.

Nov 15 '05 #5
Looks like I need to master regular expression to do this.

I'll try to construct a better and robust reg exp and I'll come back later
for the solution. (in case somebody else stumbled on the same problem)

Thanks everybody.

"Picho" <pi***********@telhai.ac.il> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
Ahmad,

Why don't you use regular expressions?

string expression = "\"1\",\"two\",\" three\", \"fo\"\"ur\", \"fi,ve\"";
MatchCollection col = Regex.Matches(expression,
@"(?:^|\s*\,\s*)(?:""(?<SubString>(?:""""|[^""])*)"")+",RegexOptions.IgnoreC ase | RegexOptions.IgnorePatternWhitespace);
foreach (System.Text.RegularExpressions.Match match in col)
{
string subString = match.Groups["SubString"].Value;
}

dont forget to use namespace System.Text.RegularExpressions

B.T.W - it doesnt work if the first substring (1) is not surrounded with "
as well...

Picho
"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to
split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.

Thank you.

*- character "[" and "]" denotes the start and end of string.


Nov 15 '05 #6
Sorry I really didn't notice the "fi,ve" string in the first place. In this
case, Regular Expressions are the way to go, as other people have advised.
They are not so complex to be mastered, and they are really powerful!

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
It does the job but notice the last string - "fi,ve". Split method will
split that string into 2. "fi" and "ve".

My point here is to not split the string in between the starting "
charachter and the closing " until it reached a comma.

Another issue is to include the " character itself, like in a string:
string s = "6,\"as\"\"a;s,d\",\"normal string\"";

Typical split will split the string into {"6", "\"as\"\"a;s", "d\"",
"\"normal string\""};
I wish I can split it into {"6", "\"as\"\"a;s,d\"", "\"normal string\""}

I hope you can see my point.

Please help.

p/s: refer to MSSQL DTS Import/Export Wizard. It does the job so well.
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2*****************@TK2MSFTNGP11.phx.gbl...
Hi,

Doesn't the String.Split method with comma char specified as a separator

do
the job?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.
Thank you.

*- character "[" and "]" denotes the start and end of string.



Nov 15 '05 #7
Sorry I really didn't notice the "fi,ve" string in the first place. In this
case, Regular Expressions are the way to go, as other people have advised.
They are not so complex to be mastered, and they are really powerful!

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
It does the job but notice the last string - "fi,ve". Split method will
split that string into 2. "fi" and "ve".

My point here is to not split the string in between the starting "
charachter and the closing " until it reached a comma.

Another issue is to include the " character itself, like in a string:
string s = "6,\"as\"\"a;s,d\",\"normal string\"";

Typical split will split the string into {"6", "\"as\"\"a;s", "d\"",
"\"normal string\""};
I wish I can split it into {"6", "\"as\"\"a;s,d\"", "\"normal string\""}

I hope you can see my point.

Please help.

p/s: refer to MSSQL DTS Import/Export Wizard. It does the job so well.
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2*****************@TK2MSFTNGP11.phx.gbl...
Hi,

Doesn't the String.Split method with comma char specified as a separator

do
the job?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ahmad A. Rahman" <je************@yahoo.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string as [1,"two"," three", "fo""ur", "fi,ve"] and I want to split the string, which will turn into an array of:
Arr[0] = "1";
Arr[1] = "two";
Arr[2] = "three";
Arr[3] = "fo""ur";
Arr[4] = "fi,ve";

This has to be possible, but I really don't know the logic. Please help.
Thank you.

*- character "[" and "]" denotes the start and end of string.



Nov 15 '05 #8

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

Similar topics

2
by: GIMME | last post by:
I can't figure an expression needed to parse a string. This problem arrises from parsing Excel csv files ... The expression must parse a string based upon comma delimiters, but if a comma...
4
by: Matt | last post by:
Hi there, I'm having a weird situation when converting strings to double. Normally, the following code would work right? double MyDouble = double.Parse("20.50"); // Error at runtime Well,...
8
by: Ahmad A. Rahman | last post by:
Hi all, I have a problem constructing a regular expression using .net. I have a string, separated with comma, and I want to group the string together but, I failed to group a numeric character...
4
by: Jesper Denmark | last post by:
Hi, I use the double.Parse functionality to convert a number in a text file into a double. However, while this works fine on one computer it doesn't on another. I've found out that it is...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
4
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I'm using greece - greek in my control panel's regional options, and so, my decimal point is the comma (,), while it is the dot (.) for the sql server db, however, I'm facing...
2
by: apattin | last post by:
Hi all, I have a table containing MEASURE DOUBLE. I want to SELECT measure FROM mytable WHERE <condition> If measure = 1860.45, I get: '1,860.45'. How can I strip the comma? I tried: ...
2
by: Earl | last post by:
Anyone know why the RowFilter has to be double-escaped? Anticipating names with apostrophes, a single escape does not provide the proper name to filter on. For example, this would cause an...
9
by: AGP | last post by:
I've been scratching my head for weeks to understand why some code doesnt work for me. here is what i have: dim sVal as string = "13.2401516" dim x as double x = sVal debug.writeline ( x)
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
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,...
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
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.