How to specify codes like [#13] - Forum

Forum Navigation
You need to log in to create posts and topics.

How to specify codes like [#13]

When you show the contents a multi-line text file in a Container object, the line feeds (CR LF) are ignored; so I thought I would replace the CRLF strings with <br/> like this ...

StrReplace "[content]" "[#13][#10]" "<br/>" [content] ""

... whenever this command is scripted in an App, it hangs.

Is there a best practice for specifying CRLF (and other [#xx] ascii codes) in commands of VisualNEOWeb ?

Hi @Gaev,

The problem with [#13] and [#10] is that, although they are valid and broadly used in VisualNEO Win, they are not valid JavaScript names for variables.
As they use brackets, VisualNEO Web try to use #13 and #10  as variables and stops working because the syntax error.
You can check here if a given variable name is valid.

They only way I can think right now to solve the problem is with this code:

BeginJS
  $App.content = $App.content.replace('[#13][#10]', '<br/>');
EndJS

 

@luishp:

Yes, I ended up doing something similar ...

SetVar [htmlText] ""

BeginJS
       //fetch [plainText]
       var plainTextJS = $App.plainText;
       //alert(plainTextJS);

       //replace all occurences
       var htmlTextJS = plainTextJS.replace(/\r\n/g, "<br/>");
       //alert(htmlTextJS);

       //store result in [htmlText]
       $App.htmlText = htmlTextJS;
EndJS

... which takes the content of variable [plainText] (including CR and LF characters) and returns the equivalent html (i.e. <br/>) in variable [htmlText]

Note that ...

a) you can use \r\n to define CR and LF codes

b) the javascript .replace method only replaces the first matching occurrence by default; so you have to use the regex notation to replace all occurences.

 

luishp has reacted to this post.
luishp