Recover special characters ('\n', '\t', etc) from Field.

Hey all, I am having some troubles being able to retain special characters when I use a field DBE. I want to be able to input things like newlines, tabs, etc. when appending attribute values but all I'm getting as an output is just the text itself (so "\n6512" instead of a newline+"6512"). I know I could search for them (each individually) using regex and replace all them manually, but is there an easier way?? Thanks!

- nm3210
SystemAdmin - Thu Apr 04 08:12:25 EDT 2013

Re: Recover special characters ('\n', '\t', etc) from Field.
Tony_Goodman - Thu Apr 04 08:58:42 EDT 2013

Maybe you should use a richText DBE instead?

Tony Goodman, www.smartdxl.com

Re: Recover special characters ('\n', '\t', etc) from Field.
SystemAdmin - Thu Apr 04 09:14:05 EDT 2013

Tony_Goodman - Thu Apr 04 08:58:42 EDT 2013
Maybe you should use a richText DBE instead?

Tony Goodman, www.smartdxl.com

Well then I'm left with all the rich text junk: "{\rtf1\fbidis\ansi\ansicpg936\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\ltrpar\lang1033\f0\fs20 TEST\par}"

I figured that if there was an easy way to do this you (or another of the experienced guys here) would probably know off the top of your head, so maybe it's just not easily doable? Like a lot of things, it's not completely necessary and you can skirt your way around it. Thanks for the response Tony! I definitely got a lot of help from your website when I first started coding DXL.

Re: Recover special characters ('\n', '\t', etc) from Field.
Mathias Mamsch - Thu Apr 04 13:46:02 EDT 2013

SystemAdmin - Thu Apr 04 09:14:05 EDT 2013
Well then I'm left with all the rich text junk: "{\rtf1\fbidis\ansi\ansicpg936\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\ltrpar\lang1033\f0\fs20 TEST\par}"

I figured that if there was an easy way to do this you (or another of the experienced guys here) would probably know off the top of your head, so maybe it's just not easily doable? Like a lot of things, it's not completely necessary and you can skirt your way around it. Thanks for the response Tony! I definitely got a lot of help from your website when I first started coding DXL.

Well maybe there is a misunderstanding. First of all, the field DBE can only contain a one line string, so newline characters, etc. are simply not rendered there, but the text appears to be in one line. There is a text DBE and a richText DBE which both support multi line strings the latter one richText formatted.

What I do not understand is that you write, that in your field you see "\n1234" instead of "newline 1234". What exactly is it, you are setting in your field? Can you post a little example to make more obvious what the problem is, e.g.
 

DB x = centered "Test" 
 
DBE y = text(x, "", "", 80, 100, false) 
realize x
 
set (y, "abc\ndef")
 
show x

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Recover special characters ('\n', '\t', etc) from Field.
llandale - Thu Apr 04 14:03:18 EDT 2013

SystemAdmin - Thu Apr 04 09:14:05 EDT 2013
Well then I'm left with all the rich text junk: "{\rtf1\fbidis\ansi\ansicpg936\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\ltrpar\lang1033\f0\fs20 TEST\par}"

I figured that if there was an easy way to do this you (or another of the experienced guys here) would probably know off the top of your head, so maybe it's just not easily doable? Like a lot of things, it's not completely necessary and you can skirt your way around it. Thanks for the response Tony! I definitely got a lot of help from your website when I first started coding DXL.

Don't know so I came up with the following. Enter some text into the Rich Text box, bold some, then hit Check. It appears you need to manually prefix the string with "{rtf1 " and suffix it with "}". The "richText(text)" command didn't work. Very odd, clearly I'm missing something.

DB db
DBE dbeT, dbeR, dbeX
 
string colourstring = 
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharse
t0 Arial;}} 
{\\colortbl 
;\\red255\\green0\\blue0;\\red255\\green0\\blue255;\\red0\\green0\\blue128;} 
\\viewkind4\\uc1\\pard\\f0\\fs20 Some\\cf1\\b  text \\b0\\cf0 with \\cf2 different\\cf0  
\\cf3 colors\\cf0  in it.\\par 
\\par 
}"      // string from DXL manual bottom of "Common element operations"
 
void applyCheck(DB dbXX)
{
   string Text = get(dbeR)
   string Set = ("{\\rtf1 == Raw >>" (get(dbeT))"<<\n== Rich >>" Text "<<}")
   //Set = richText("== Raw >>" (get(dbeT))"<<\n== Rich >>" Text "<<")
   print Set
   set(dbeX, Set)
}
 
db = create("Compare RawText with RichText DBEs")
dbeT = text    (db, "Raw Text", "", 300, 100, false)
dbeR = richText(db, "RichText", richText(""), 300, 100, false)
dbeX = richText(db, "Result", "", 300, 150, true)
 
apply(db, "Check", applyCheck)
realize(db)
set(dbeX, colourstring)
 
show(db)


-Louie

Re: Recover special characters ('\n', '\t', etc) from Field.
SystemAdmin - Fri Apr 05 11:41:58 EDT 2013

Mathias Mamsch - Thu Apr 04 13:46:02 EDT 2013

Well maybe there is a misunderstanding. First of all, the field DBE can only contain a one line string, so newline characters, etc. are simply not rendered there, but the text appears to be in one line. There is a text DBE and a richText DBE which both support multi line strings the latter one richText formatted.

What I do not understand is that you write, that in your field you see "\n1234" instead of "newline 1234". What exactly is it, you are setting in your field? Can you post a little example to make more obvious what the problem is, e.g.
 

DB x = centered "Test" 
 
DBE y = text(x, "", "", 80, 100, false) 
realize x
 
set (y, "abc\ndef")
 
show x

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

> Mathias Mamsch wrote:
> Well maybe there is a misunderstanding. First of all, the field DBE can only contain a one line string, so newline characters, etc. are simply not rendered there, but the text appears to be in one line. There is a text DBE and a richText DBE which both support multi line strings the latter one richText formatted.
>
> What I do not understand is that you write, that in your field you see "\n1234" instead of "newline 1234". What exactly is it, you are setting in your field? Can you post a little example to make more obvious what the problem is, e.g.
>
> Regards, Mathias

I'm not trying to get the newline to be show up in the input text field, that would be silly. I want to input general text (which would include some of the ASCII ctrl characters Char<31 including '\n', '\t', etc) and place that text into an object's attribute with a Text/String basetype (which WOULD show you the newline, tab, etc).
 

DB DialogBox = create("Replace Object Text",styleCentered|styleFloating)
DBE TextField = field(DialogBox,"New text:","Testing newline:\\n\\tNope.",30)
void toApply(DB db){(current Object)."Object Text" = get(TextField);refresh(current Module)}
void toNewLine(DB db){(current Object)."Object Text" = "Testing newline:\n\tYes.";refresh(current Module)}
apply(DialogBox,"New Line",toNewLine)
apply(DialogBox,"Apply Text",toApply)
show DialogBox

 


I guess the question really becomes how to un-escape text so that you may retain/recover/reinterpret special characters. Once placed, the text that includes the literal "\n" is indeed just Char92+Char110 whereas the interpreted text replaced that with a Char10. Again, I understand how to replace something like that with regex pretty trivially, but I would rather not have to run a different regex/replace for all the ASCII control characters (realistically you might only need to use a few, but that's not really my point).

 

Re: Recover special characters ('\n', '\t', etc) from Field.
Adamarla - Wed May 08 03:26:10 EDT 2013

SystemAdmin - Fri Apr 05 11:41:58 EDT 2013

> Mathias Mamsch wrote:
> Well maybe there is a misunderstanding. First of all, the field DBE can only contain a one line string, so newline characters, etc. are simply not rendered there, but the text appears to be in one line. There is a text DBE and a richText DBE which both support multi line strings the latter one richText formatted.
>
> What I do not understand is that you write, that in your field you see "\n1234" instead of "newline 1234". What exactly is it, you are setting in your field? Can you post a little example to make more obvious what the problem is, e.g.
>
> Regards, Mathias

I'm not trying to get the newline to be show up in the input text field, that would be silly. I want to input general text (which would include some of the ASCII ctrl characters Char<31 including '\n', '\t', etc) and place that text into an object's attribute with a Text/String basetype (which WOULD show you the newline, tab, etc).
 

DB DialogBox = create("Replace Object Text",styleCentered|styleFloating)
DBE TextField = field(DialogBox,"New text:","Testing newline:\\n\\tNope.",30)
void toApply(DB db){(current Object)."Object Text" = get(TextField);refresh(current Module)}
void toNewLine(DB db){(current Object)."Object Text" = "Testing newline:\n\tYes.";refresh(current Module)}
apply(DialogBox,"New Line",toNewLine)
apply(DialogBox,"Apply Text",toApply)
show DialogBox

 


I guess the question really becomes how to un-escape text so that you may retain/recover/reinterpret special characters. Once placed, the text that includes the literal "\n" is indeed just Char92+Char110 whereas the interpreted text replaced that with a Char10. Again, I understand how to replace something like that with regex pretty trivially, but I would rather not have to run a different regex/replace for all the ASCII control characters (realistically you might only need to use a few, but that's not really my point).

 

So, here you go:

 

string Unescape(string sEscaped)
{
if(!null(checkDXL("\"" sEscaped "\""))) { return("") }
return(eval_("return_(\"" sEscaped "\")"))
}

DB DialogBox = create("Replace Object Text",styleCentered|styleFloating)
DBE TextField = field(DialogBox,"New text:","Testing newline:\\n\\tNope.",30)

void toPrint(DB db)
{
string sEscaped = get(TextField);
print("sEscaped: " sEscaped "\n")
string sUnescaped = Unescape(sEscaped)
if(!null(sEscaped) and null(sUnescaped)) {
  print("ERROR: Incorrectly escaped string\n")
} else {
  print("sUnescaped: " sUnescaped "\n")
}
}

void toApply(DB db)
{
string sEscaped = get(TextField);
string sUnescaped = Unescape(sEscaped)
if(!null(sEscaped) and null(sUnescaped)) {
  return()
}

 (current Object)."Object Text" = sUnescaped;
refresh(current Module)
}

void toNewLine(DB db)
{
(current Object)."Object Text" = "Testing newline:\n\tYes.";
refresh(current Module)
}
apply(DialogBox,"New Line", toNewLine)
apply(DialogBox,"Apply Text", toApply)
apply(DialogBox,"Print", toPrint)
show DialogBox

Re: Recover special characters ('\n', '\t', etc) from Field.
nm3210 - Thu May 09 08:10:24 EDT 2013

Adamarla - Wed May 08 03:26:10 EDT 2013

So, here you go:

 

string Unescape(string sEscaped)
{
if(!null(checkDXL("\"" sEscaped "\""))) { return("") }
return(eval_("return_(\"" sEscaped "\")"))
}

DB DialogBox = create("Replace Object Text",styleCentered|styleFloating)
DBE TextField = field(DialogBox,"New text:","Testing newline:\\n\\tNope.",30)

void toPrint(DB db)
{
string sEscaped = get(TextField);
print("sEscaped: " sEscaped "\n")
string sUnescaped = Unescape(sEscaped)
if(!null(sEscaped) and null(sUnescaped)) {
  print("ERROR: Incorrectly escaped string\n")
} else {
  print("sUnescaped: " sUnescaped "\n")
}
}

void toApply(DB db)
{
string sEscaped = get(TextField);
string sUnescaped = Unescape(sEscaped)
if(!null(sEscaped) and null(sUnescaped)) {
  return()
}

 (current Object)."Object Text" = sUnescaped;
refresh(current Module)
}

void toNewLine(DB db)
{
(current Object)."Object Text" = "Testing newline:\n\tYes.";
refresh(current Module)
}
apply(DialogBox,"New Line", toNewLine)
apply(DialogBox,"Apply Text", toApply)
apply(DialogBox,"Print", toPrint)
show DialogBox

Awesome!! (These were my posts) Major props to you for figuring this out. I assume it just re-parses the string through eval_ so you get the re-interpreted characters? Seems straightforward enough, I definitely did not think of using eval though!

Re: Recover special characters ('\n', '\t', etc) from Field.
llandale - Thu May 09 11:21:32 EDT 2013

Tony_Goodman - Thu Apr 04 08:58:42 EDT 2013
Maybe you should use a richText DBE instead?

Tony Goodman, www.smartdxl.com

...or just a "text" DBE.

Re: Recover special characters ('\n', '\t', etc) from Field.
Adamarla - Fri May 10 01:10:27 EDT 2013

nm3210 - Thu May 09 08:10:24 EDT 2013

Awesome!! (These were my posts) Major props to you for figuring this out. I assume it just re-parses the string through eval_ so you get the re-interpreted characters? Seems straightforward enough, I definitely did not think of using eval though!

"I assume it just re-parses the string through eval_ so you get the re-interpreted characters?"

Exactly. You are entering a string which is escaped the same way as writing a string literal in dxl code. I just surround it with quotes and use eval_ to get dxl to do its thing and unescape it.