I have a Paragraph which has text along with several variables. I want to replace the variables with values (text) I read from an INI file at runtime. Is there a way to do this in one step? I have been using labels for single words.
Professional Software Development Tools
I have a Paragraph which has text along with several variables. I want to replace the variables with values (text) I read from an INI file at runtime. Is there a way to do this in one step? I have been using labels for single words.
Last edited by cchian; 04-27-2004 at 01:57 PM. Reason: better title
A way to it:
Create a stringvariable wit text and placeholder
longtext=[[bla bla bla %VAR_1% bla bla bla bla bla bla bla
bla bla bla bla bla bla %VAR_2% bla bla bla bla bla bla
bla bla bla bla bla bla %VAR_3% bla bla bla bla bla bla
bla bla bla bla bla bla %VAR_4% bla bla bla bla bla bla]]
run loop for all variables
for x,max do
result = String.Replace(longtext, "%VAR_"..x.."%", your ini[x], false);
end
write text to paragraphobject
Paragraph.SetText("paragraph1", longtext);
hope it helps
Stefan
Thanks, I will give that a try. Another question, if my paragraph only contains very few items (ie Product name, Version and Build), is your example still the quickest way of doing it?
maybe a faster way:
--fix text
text_part1="bla bla bla "
text_part2="blo blo blo "
text_part3="bli bli bli "
text_part4="ble ble ble "
text_part4="blu blu blu "
--concat fixed text with inivariables
longtext=text_part1..inivar1..text_part2..inivar2. .text_part3..inivar3..text_part4..inivar4..text_pa rt5;
--write text to paragraphobject
Paragraph.SetText("paragraph1", longtext);
Stefan
Yep Stefan M's right. A good rule of thumb is too, use his first method if you will be doing more than one replace during your project, use the second for scenarios where you will be setting those values once-per-run.
I use ###TEXT### usually for my replace values, works good and eliminates any chance you may accidentally replace something unrelated. For example
text="Hi ###NAME###, How are you. Today's date is ###DATE###.";
And then you can use a String replace to swap the name anad date values. That's just one example, you can use anything really but it's good to create a habit for one method or the other right from the start, for your own reference.
Corey Milner
Creative Director, Indigo Rose Software
How can I show the results in different lines? Like in:
Product name: My App
Version 1.0
Build 1234
I tried adding "\n" but I keep getting errors. This is what I have:
longtext = "Product Name "..strname \n "Version "..strversion \n "Build "..strbuild;
Paragraph.SetText("Paragraph1", longtext);
Try:
Example:
Dialog.Message("", "Hi\n\r\There!");
Last edited by Intrigued; 04-27-2004 at 10:43 PM.
Intrigued
Hi.
longtext = "Product Name "..strname.."\\n Version "..strversion.."\\n Build "..strbuild;
Corey Milner
Creative Director, Indigo Rose Software
It is still concatenating everything together connected by "\n".![]()
Originally Posted by Corey
longtext = "Product Name: "..strname.."\r\n Version: "..strversion.."\r\n Build: "..strbuild;
Hmmm, works OK here. Here I've attached a working example, actions are Page OnShow. Just pick it apart and re-use what you need.Hi Stefan, just FYI you don't actually need the \r for a paragraph object but if you were going to use it, you would want to use this syntax FWIW:
![]()
longtext = "Product Name: "..strname.."\\r\\n Version: "..strversion.."\\r\\n Build: "..strbuild;
Main thing is escaping the slashes. Like Zorro!
Corey Milner
Creative Director, Indigo Rose Software
Stefan M, your example works perfectly. Corey, I still had the same results as before using your example. It is strange that it behaves different in your PC.
Thanks for the help!
Yes that is very strange, the example project should work fine on any PC in AMS. But anyoo.
Corey Milner
Creative Director, Indigo Rose Software
Actually, Corey, in this case you don't want to escape the slashes. If you do that, the slashes (and the 'r' and 'n') will appear in the text.Originally Posted by Corey
--[[ Indigo Rose Software Developer ]]