Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Escape Commas in TStrings.CommaText assignment

Posted on 2003-11-12
12
Medium Priority
?
1,347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

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

Technology Partners: 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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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