Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 2 Jahren, 4 Monaten
Letzter Beitrag:
vor 2 Jahren, 4 Monaten
Beteiligte Autoren:
Yogi Yang, DarrenF, Ola, Mike H, Paulo Oliveira, Piet van Zanten

How to build such complex strings with double quotes easily?

Startbeitrag von Yogi Yang am 02.02.2016 10:44

Hello,

I am trying to build a string which is getting a bit too long as it contains double quotes.

Here is the code:

bufRetValueBuffer = Charact(34) + "ok" + Charact(34) + "," + Charact(34) + Charact(34) + "," + Charact(34) + Charact(34) + "," + Charact(34) + Charact(34) + "," + Charact(34) + Charact(34)

I should the string like this:
Quote

"ok","","","",""


Is there any easier way to build strings with quotes (single as well as double)?

TIA

Yogi Yang

Antworten:

Just doudle them or use the sintax:

my_string is string=[
aaa "bb" ccc
]

http://doc.windev.com/en-US/?1514044
http://doc.windev.com/en-US/?1512011

von Paulo Oliveira - am 02.02.2016 12:46
Hi, Yogi.
Two suggestions:
1. The quick and dirty way is to define a 1-character string for double quotes
DQ is string=Charact(34)

Your command would look like
bufRetValueBuffer=DQ+"ok"+DQ+","+DQ+DQ+","+DQ+DQ+","

2. A fancier way would be to define a procedure (local or global)
PROCEDURE DQ(x)
RESULT Charact(34)+x+Charact(34)

Your command would look like
bufRetValueBuffer=DQ("ok")+","+DQ("")+","+DQ("")

von Mike H - am 02.02.2016 12:48
Hi Yogi,

I think you can use triple quotes.
For better readability you could also use:
bufRetValueBuffer = Replace("-ok-,--,--,--","-",Charact(34))
or
bufRetValueBuffer = StringBuild("%1ok%1,%1%1,%1%1,%1%1",Charact(34))

Regards,
Piet

von Piet van Zanten - am 02.02.2016 12:50
Hi Yogi

In addition to the other suggestions:
If the length of the line is a problem, as you said, you can cut it into two or more lines with ... (three periods). Like:


DQ is string=Charact(34)

bufRetValueBuffer=DQ+"ok"+DQ+...
","+DQ+DQ+","+DQ...
+DQ+","


best regards
Ola

von Ola - am 02.02.2016 12:55
You could also try building a string that contains "%1","%2","%3",... as many as you need.

Then StringBuild(YourString,Forename,Surname,Address1...)

Then you would see something like "Fred","Bloggs","1 High Street",...

Don't forget, you can also use arrays to build the content :spos:

http://help.windev.com/en-US/?3024006&name=stringbuild_function

von DarrenF - am 02.02.2016 13:40
Quote
Paulo Oliveira
Just doudle them or use the sintax:
my_string is string=[
aaa "bb" ccc
]

Paulo,

Thanks for the hint. It works perfectly and as I need it. Instead of adopting suggestions by others I prefer to go with your suggestion. It is easier and cleaner.

Thank you,

Yogi Yang

von Yogi Yang - am 02.02.2016 13:54
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.