I’ve building a string using python then writing that string into a string tag.
In building the string I am attempting to add line feeds/carriage returns using the ‘\r\n’ escape characters.
What I actually see in the string tag is a space where there should be a new line.
So the code looks something like this:
myStr = ''
for i in range(1, 10):
myStr += 'This is line ' + str(i) + '.\r\n'
resp = system.tag.write('myStrTag', myStr)
If I run this is the Script Console with a print statement at the end I see the output as:

When I look at the content of the string I see this:
This is line 1. This is line 2. This is line 3. This is line 4. This is line 5. This is line 6. This is line 7. This is line 8. This is line 9.
This string will get written to a text field in a database table and is NOT written to a file. Is there anyway to format the string so that when it is written to the table the formatting is correct?
Thanks.
If you read in the tag with system.tag.read() and print it in the console, what’s the result?
The codes are there. Display objects that expect a single line of text will show just a single line, obscuring the line endings. Like the Tag Browser and text edit fields. Bind your string tag to a text area instead, and see what you get.
1 Like
It’s still there. Really! However, depending on what you’re pulling the string back into, you may have to format in html.
So,for example, an html formatted string like this:

will show in a label component as:

bfusion
It looks to be formatting correctly when printed to the Output Console.
I did notice too, that when I copy the string from the database and paste it into Notepad it seems to be formatting properly.
My concern was due do the content of the string tag, when copied and pasted to Notepad was just one continuous stream of text with no line feeds.
Jordan,
As noted, the string is part of an update query to a SQL table. The destination is a Text column in SQL.
I’m just not sure how the other system processes the data and if this is important.
The string is actually XML formatted data. I didn’t mention that before because I didn’t want to complicate the conversation as I have that part worked out.
Thanks.
pturmel,
It seems kind of strange to me that the tag content, when copied and pasted to Notepad does NOT format like I would expect, but when I copy/paste the the Text field content from the database to Notepad it formats like I would expect, with the line feeds.
Disclaimer: I haven’t read through the entire thread, but:
This is probably a Notepad bug - Notepad, for all time, requires Windows line endings (CRLF) and wouldn’t interpret a single LF as a newline. Some part of how you’re writing the value to the tag is probably collapsing CRLF into just LF (possibly the tag itself) and then Notepad doesn’t know how to handle it.
Alternately, the text field has specific code when you copy, where Java says “this is a Windows system, so I’ll copy it using Windows line endings”.
2 Likes
I’m using both the carriage return and line feed escape characters, \r\n, which is the Windows standard.
It seems to be OK once it’s in the database so I’m going to call it GOOD!
3 Likes