boardtc
asked on
Escape Commas in TStrings.CommaText assignment
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.
TStrings.CommaText := 'Create,Update'',''Delete,
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.
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:Empt y';
Produces:
MyStringList[0] - 'Create,Update'
MyStringList[1] - 'Delete'
MyStringList[2] - 'Empty'
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:Empt
Produces:
MyStringList[0] - 'Create,Update'
MyStringList[1] - 'Delete'
MyStringList[2] - 'Empty'
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",Em pty';
This will give you
TStrings.Strings[0] = Create
TStrings.Strings[1] = Update,Delete
TStrings.Strings[2] = Empty
Hopt that helps,
...Snehanshu
So, you need:
TStrings.CommaText := 'Create,"Update,Delete",Em
This will give you
TStrings.Strings[0] = Create
TStrings.Strings[1] = Update,Delete
TStrings.Strings[2] = Empty
Hopt that helps,
...Snehanshu
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",Em pty';
Also, note that " is double quote and NOT two quotes like ''
:-)
...Snehanshu
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
Also, note that " is double quote and NOT two quotes like ''
:-)
...Snehanshu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect. thanks!
tom.
tom.
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 ;-)
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 ;-)
ASKER
opps, please reassing points to Snehanshu. thanks, tom.
ASKER
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.
Thanks, Tom.
doesn't matter,
i gave Snehanshu the same points from
my question-points, so i guess, there must be no action taken
meikl ;-)
i gave Snehanshu the same points from
my question-points, so i guess, there must be no action taken
meikl ;-)
ASKER
thanks for that, tom.
Thank you tomcorcoran. No problemo!
kretzschmar has passed the points to me.
https://www.experts-exchange.com/questions/20807210/for-Snehanshu.html
Cheers!
...Shu
kretzschmar has passed the points to me.
https://www.experts-exchange.com/questions/20807210/for-Snehanshu.html
Cheers!
...Shu
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,
SourceStr:=StringReplace(S
StrList.CommaText:= SourceStr;
for i:= 0 to StrList.Count-1 do
if Pos('_',StrList[i]) > 0 then
StrList[i]:= StringReplace(StrList[i],'
Abdelghani