5

I would like to left-pad spaces in a string as needed so it is always 8 characters long. I would also like to limit the initial string to 8 characters. Example:

Given string of "1234", should become "\s\s\s\s1234"

Given string of "123456789", should become "12345678"

I've tried "Scan From String" function using a format specifier of %8.8s, which I thought should limit the original length to 8 or less characters, and then pad spaces as necessary, to ensure a maximum of 8 characters in total.

I was expecting "1234" text to be turned into " 1234" but it just returned "1234".

It's labview "G" code so I can't enter text code.

Ramon
  • 1,415
  • 9
  • 18

1 Answers1

4

You did not include a picture, so I am not sure if you are using the right VI, but you should be using the Format Into String VI. The parameter that you are looking for is called Width (see more about specifier syntax here).

Here is how you would use that to do what you are asking:

enter image description here enter image description here

To see the spaces, make sure the string constant or indicator is set to view slash codes

des
  • 125
  • 6
  • 1
    That worked. I was using the "Scan into String" function, not "Format into String". By using %8.8s (instead of "%8s") I am able to also truncate long strings to 8 chars in addition while keeping the padding. Thanks for quick reply. – Pablo Bridges Aug 23 '19 at 20:02
  • @des : second sentence. :-) – srm Aug 24 '19 at 18:55