LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

string fixed width

Hello, anybody knows how to create strings with a fixed width? I will restrict the lenght of strings, which put the user in a field to a defined maximum. The best would be, if the generated strings have the same length. The problem what I have actual is, I put the strings in an array and generate afterwards a spreedsheet string. When I put these spreedsheet string afterwards again in an array to modify some entrys with a shorter length, the difference is still in the array element. Thank you.
0 Kudos
Message 1 of 5
(5,028 Views)

to limit the allowed entry length of a string capture the string key down/key repete events and check the new values length, if too long write the old string to a local or property value of the string control.  To fix the size of a string after entry, uos a componation of string length and string subset (to shorten strings) or concatinate (prepend n space characters to the string)  You could even get fancy and do this all in an x control.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 2 of 5
(5,018 Views)
Your question seems to imply that you want the program to generate the strings, rather than a user. That being the case, what criteria do you have for generating the strings? Are you just looking for a string of, say, 10 spaces? Or a string of 10 random characters? The easiest way to generate a fixed-length string to create an array of U8 integers which are the ASCII codes for the characters, and then use the Byte Array to String function, as shown below using an example of a string of 10 spaces:


Message Edited by smercurio_fc on 08-27-2007 02:54 PM

0 Kudos
Message 3 of 5
(4,993 Views)

LabVIEW does not have a fixed lenght string datatype. If you want to pad entries to a fixed lenght, you need to decide what the pad character should be. When you are converting back from a spreadhseet string, you again need to be careful that the pad characters are not recognized as separators.

IF you really have an array of all fixed lenght strings of the same lenght in your file, you should consider a binary format for your files.

What is the lenght of each string? If is is e.g. only 8 charcacters, you could cast it to a U64 numeric, for example.

0 Kudos
Message 4 of 5
(4,986 Views)
altenbach said

LabVIEW does not have a fixed lenght string datatype.

Correct, of course. I did not mean to imply that you actually got a fixed length string using the Byte Array to String. Only that you got strings of some arbitrary pre-determined length. The string itself can still vary.
Message 5 of 5
(4,974 Views)