?
Solved

Escape Commas in TStrings.CommaText assignment

Posted on 2003-11-12
12
Medium Priority
?
1,349 Views
Last Modified: 2007-12-19
I want to assign a TStrings.CommaText to include commas, so I would like to be able to do something like :

  TStrings.CommaText := 'Create,Update'',''Delete,Empty';
so
  TStrings.Strings[0] = Create
  TStrings.Strings[1] = Update,Delete
  TStrings.Strings[2] = Empty

Is there any way to escape a comma in this assignment?

Thanks, Tom.
0
Comment
Question by:boardtc
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 1

Expert Comment

by:Gani2001
ID: 9736432
Hi there
try to use this Simple Code

at first Declare this three Variable
 i: integer;
 SourceStr: string;
 StrList: TStringList;

and this the procedure body

StrList:= TStringList.Create;
SourceStr:= 'Create,Update'',''Delete,Empty';
SourceStr:=StringReplace(SourceStr,''',''','_',[rfReplaceAll,rfIgnoreCase]);
StrList.CommaText:= SourceStr;
for i:= 0 to StrList.Count-1 do
if Pos('_',StrList[i]) > 0 then
   StrList[i]:= StringReplace(StrList[i],'_',',',[rfReplaceAll,rfIgnoreCase]);

Abdelghani
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 9736986
Change the delimiter to something else, such as : and then use DelimitedText
instead of CommaText to Assgn the items. You can then also use CommaText
after assignment to get your items the same as using DelimitedText, or rather
the two calls will produce the same result.


MyStringList.Delimiter := ':';

// MUST BE NO SPACES because space is by default a delimiter
// in a stringlist when using CommaText or DelimitedText.
MyString.DelimitedText :=  'Create,Update:Delete:Empty';

Produces:
MyStringList[0] - 'Create,Update'
MyStringList[1] - 'Delete'
MyStringList[2] - 'Empty'
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9737173
To include commas in a comma-delimited text, you need to wrap the whole string into double quotes, not only the comma as you have done.
So, you need:
TStrings.CommaText := 'Create,"Update,Delete",Empty';

This will give you
  TStrings.Strings[0] = Create
  TStrings.Strings[1] = Update,Delete
  TStrings.Strings[2] = Empty

Hopt that helps,
...Snehanshu
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:snehanshu
ID: 9737462
tomcorcoran
  I guess you are aware of this but just for clarification: You cannot use TStrings class directly, so you would have to do it in some stringlist or combobox's items like
MyComboBox.Items.CommaText := 'Create,"Update,Delete",Empty';

 Also, note that " is double quote and NOT two quotes like ''
:-)
...Snehanshu
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 total points
ID: 9745870
too late ;-(

thats it, Snehanshu
0
 

Author Comment

by:boardtc
ID: 9810973
perfect. thanks!

tom.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9811025
ehm,
guessing this was a grade by mistake,
i did not solved anything on this q

which one should be correct be graded, tom?
(i would then post q for this expert)

meikl ;-)
0
 

Author Comment

by:boardtc
ID: 9811347
opps, please reassing points to Snehanshu. thanks, tom.
0
 

Author Comment

by:boardtc
ID: 9835977
Snehanshu, sorry about this mistake. One used to be able to post a message on the community board but the format seems to have changed. Do you know how I can chnage the acepted answer from  kretzschmar to you?

Thanks, Tom.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9836115
doesn't matter,
i gave Snehanshu the same points from
my question-points, so i guess, there must be no action taken

meikl ;-)
0
 

Author Comment

by:boardtc
ID: 9836237
thanks for that, tom.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9842426
Thank you tomcorcoran. No problemo!
kretzschmar has passed the points to me.
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20807210.html
Cheers!
...Shu
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question