Solved

Escape Commas in TStrings.CommaText assignment

Posted on 2003-11-12
12
1,301 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:tomcorcoran
  • 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:EddieShipman
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
 
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 75 total points
ID: 9745870
too late ;-(

thats it, Snehanshu
0
 

Author Comment

by:tomcorcoran
ID: 9810973
perfect. thanks!

tom.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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:tomcorcoran
ID: 9811347
opps, please reassing points to Snehanshu. thanks, tom.
0
 

Author Comment

by:tomcorcoran
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:tomcorcoran
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now