Solved

Escape Commas in TStrings.CommaText assignment

Posted on 2003-11-12
12
1,313 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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