I have a text file that has been read into a variable, this variable needs to be inserted into some existing text that's in a paragraph object, how would that be done?
Professional Software Development Tools
I have a text file that has been read into a variable, this variable needs to be inserted into some existing text that's in a paragraph object, how would that be done?
you could have a place holder {Holder} for that one thing and if thats in your
sting have it = "" and if then your new text that is ment to go there make it replace that place holder with the text.
Not sure how to do it 100% but i do remeber doing something on these lines before.
Bruce,
This may be a little convoluted but it should work for you, as long as you know where you want to insert the text...
LOL - some of the coding gurus could probably clean this up...Code:Insert_String = TextFile.ReadToString("AutoPlay\\Docs\\MyFile.txt"); -- text to be inserted P_Orig=Paragraph.GetText("Paragraph1"); --original paragraph -- How to determine where to insert the text file....? whereAt=String.Find(P_Orig, "jumps over the lazy", 1, false); -- search for where to insert text string -- split the paragraph text at a known point T_Front=String.Mid(P_Orig, 1, whereAt -1); -- spit variable (front) T_Back=String.Mid(P_Orig, whereAt, -1); -- spit variable (back) -- Now put them together P_New=T_Front..Insert_String..T_Back; -- insert string between front & back Paragraph.SetText("Paragraph1", P_New) -- Set and write P_New to a text file so that it's available for the paragraph next time? TextFile.WriteFromString("AutoPlay\\Docs\\MyPara.txt", P_New, false);
hth
Thx man I'll give it a go!
I need to get rid of the variable whereAt so it wont show up in the paragraph object, also, I can't write txt files back to the CD not a prob though.
Or this way...
Code:txt2Add = TextFile.ReadToString("D:\\test.txt"); newText = [[ The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ]]..txt2Add..[[ The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ]] Paragraph.SetText("Paragraph1", newText);
Nevermind...
Last edited by mwreyf1; 06-10-2009 at 03:45 PM.
if you simply want to add the text to the end of the existing text then try this
or with some error checkingCode:local sText = Paragraph.GetText("Object"); local txt2Add = TextFile.ReadToString("D:\\test.txt"); Paragraph.SetText("Object", sText.."\r\n"..txt2Add);
Code:local txt2Add = TextFile.ReadToString("D:\\test.txt"); -- Test for error error = Application.GetLastError(); if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION); else local sText = Paragraph.GetText("Object"); Paragraph.SetText("Object", sText.."\r\n"..txt2Add); end
Sounds like all you need is String.Replace. Read the paragraph to a string and set the text to be replaced (or use the variable that already contains the replacement text) like-
No no no.........Code:stxt = Paragraph.GetText("Paragraph1"); storeplace = "YOUR SALON" sreplacewith = "New salon name" snewtxt = String.Replace(stxt, storeplace, sreplacewith, false); -- the replacement text is now in the snewtxt variable ready for use.
What you want is to concatenate YOUR SALON with the additional text into a new string and *then* do a String.Replace as above.
Last edited by longedge; 06-14-2009 at 03:23 AM. Reason: Just re-read what you said - Doh....
Sounds like you have a standard application that is being resold to multiple clients and you want some of the components to be customized. How are you storing the company who purchases the product name on the application. Is there a configuration screen or text file that will store this information?
I would have a common place holder like ##COMPANYNAME## in the standard text file and then read the file into variable and replace the above place holder with the variable whereever it is stored. That way the original file would not have to change for different users. I would also add a check into the app to see if any of you placeholder variables are still present and warn the user if they still exist and maybe prompt them to supply the value at that time and then store that variable into an ini file of registry if you can.
That is how I would approach the issue.
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
Helps if I read the help file...
name_contents = TextFile.ReadToString("AutoPlay\\Docs\\business_na me.txt");
-- Read the contents of a text file into a string.
page1_contents = TextFile.ReadToString("AutoPlay\\Docs\\page1.txt") ;
-- Check the error code of the last example.
error = Application.GetLastError();
-- If an error occurred, display the error message.
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
-- Replace every occurrence of the string "BUSINESS" with the string "name_contents".
new_page1_contents = String.Replace(page1_contents, "BUSINESS", name_contents, true);
-- Write out the modified contents of the text file.
Paragraph.SetText("Paragraph1", new_page1_contents);
-- Check the error code of the last example.
error = Application.GetLastError();
-- If an error occurred, display the error message.
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
end
end