LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is the backslash (\) a printable character in format string?

I use the 'format into string' function a lot, but this is the first time I notice this. Take a look at the following code:

 

format_into_string.png

 

Please note that the format string mode is set to Normal Display. When I run it the resulting string shows 'initial_string  setup_string', so the backslash is missing. Or if I change the format string to '\setup_%s', then the resulting string looks like that 'initial_string etup_string'. It seems that even when the format string in not in '\' Codes Display mode, the backslash is not a regular printable character.

 

This is OK, but the why then the Edit Format String windows shows that the sequence ' \ setup_' produces the exact output ' \ setup_'. It should show '  setup_', without the backslash

 

edit_format_string.png

0 Kudos
Message 1 of 11
(6,941 Views)

to output a literal single "\" you use "\\" to escape the backslash. look for Backslash codes in the help file  the \ you have is not followed by a recognized hex value so it is ignored


"Should be" isn't "Is" -Jay
Message 2 of 11
(6,936 Views)

Jeff, maybe I didn't explain my question correctly. I am aware how to add the backslash to the output. I just think that:

  • The output should match the String: output in the Edit Format String window.
  • Or the String: output in the Edit Format String window shouldn't show the backslash in this case

Even the LabVIEW Format Specifier Syntax Help shows the backslash somehow related to the '\' Codes Display mode. At least this is how I understand it reading the help.

 

Nick

0 Kudos
Message 3 of 11
(6,923 Views)
Those points are valid! The help could be more helpful. Some scratch box code is warranted and feel free to hit that "submit feedback on this topic" link in the help file. NI would love to hear that.

"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 11
(6,891 Views)

I remember a discussion about this from some years ago - http://forums.ni.com/t5/LabVIEW/Format-Into-String-and-Scan-From-String-bug/m-p/631411#M292200

 

I didn't look closely, so I don't even know whether what you're seeing is the same issue or whether it is another issue, possibly caused by fixing the problem we were discussing there.


___________________
Try to take over the world!
0 Kudos
Message 5 of 11
(6,873 Views)

@tst wrote:

I remember a discussion about this from some years ago - http://forums.ni.com/t5/LabVIEW/Format-Into-String-and-Scan-From-String-bug/m-p/631411#M292200

 

I didn't look closely, so I don't even know whether what you're seeing is the same issue or whether it is another issue, possibly caused by fixing the problem we were discussing there.


The issue discussed at the link above is more about the 'Edit Format String' behavior and is still present by the way. This here is a little bit different, but also related to 'Edit Format String' and the format string of the 'Scan From ... / Format Into String' functions.

 

And I noticed also one exception which extends the inconsistency. The format strings in the two examples below are in Normal Display mode. In the second example the backslash is the last character of the format string and suddenly it becomes a regular printable character (resulting string 'text \'). In the first example there is an additional space at the end and then the backslash is missing 'text  '

 

example1.png                   example2.png

 

I think that in Normal Display mode the format strings should be interpreted exactly as they appear. The '\' Codes Display mode should handle the '\' as a control character. But I don't believe this can be changed anymore, because it will probably brake a lot of code. I will still submit a feedback to NI as suggested by Jeff already.

 

0 Kudos
Message 6 of 11
(6,834 Views)

While that sounds good, I don't think it is possible.  The format string function doesn't know what is the display format of the constant upstream of it.  It only knows the data itself.  Actually, when the code is compiled for execution the display format associated with the constant is stripped away, so the constant itself loses information about how it is displayed.

 

Whether is wouild break old code is a valid point, but the bigger problem is that if LabVIEW did account for this, it would bread future code.  I wouldn't want my code changes its manner of execution just because I happened to change the display format of a constant.

Message 7 of 11
(6,818 Views)

There is one thing about this situation that I can explain. According to the Backslash Codes Display help document, if a backslash is not follows by a Backslash non-displayable character code or a valid Hex code, then LabVIEW ignores the backslash character http://zone.ni.com/reference/en-XX/help/371361L-01/lvhowto/backslash_codes_display/. Thus, "\ " is interpreted as " ". Try experimenting with other invalid codes such as "\*", which will change to just "*". Apparently, placing a backslash at the end of the format string results in displaying the backslash exactly--as if the user input a double backslash. I will alert R&D that this should probably be explained in the documentation.

I also agree that the "output exact string" option in the Edit Format String window does not seem to handle backslashes correctly. If the user wants to be able to output the exact string, then it should change all of the backslashes to double backslashes so that the result is exactly like the user wanted. Can you confirm with me that this is what you all were refering to? If so, I will file a Corrective Action Request to R&D to ask them to address this problem.

 

Jeremy Pearson

Applications Engineer

National Instruments

Applications Engineer
National Instruments
0 Kudos
Message 8 of 11
(6,777 Views)

Iv'e wanted "Time format" codes "Output escape charater" and "Output a Single % Char" on that dialog for some time but, its easy enough to add manually to the format string so I hardly ever launch that editor. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 11
(6,760 Views)

@Prickly_Pear wrote:

...
I also agree that the "output exact string" option in the Edit Format String window does not seem to handle backslashes correctly. If the user wants to be able to output the exact string, then it should change all of the backslashes to double backslashes so that the result is exactly like the user wanted. Can you confirm with me that this is what you all were refering to? If so, I will file a Corrective Action Request to R&D to ask them to address this problem.



Jeremy,

 

Yes, I think that your suggestion will improve the Edit Format String window. In "output exact string", particularly in the corresponding format string, single backslashes could be changed to double backslashes, when they are followed by invalid backslash code, i.e. when they cannot be interpreted as a valid format string syntax element.

 

Some changes in the help maybe also helpful.

Until now when I was typing backslash codes in format strings, I was always switching to ('\') Codes Display, maybe because of this first row of the Backslash ('\') Codes Display help:

Right-click a string constant, control, or indicator and select '\' Codes Display from the shortcut menu to instruct LabVIEW to interpret characters that immediately follow a backslash (\) as a code for non-displayable characters.

So I thought that this works only in ('\') Codes Display mode I never tried to do this in Normal Display mode 🙂

 

Message 10 of 11
(6,741 Views)