From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of lines in a String

Hello all, 

i am trying to limit the number of lines entered by the user in a string control. This string will be then exported to a text file.

 

This is what i have done so far but all in vain.String_Lines.png

0 Kudos
Message 1 of 9
(4,539 Views)

Lines, in this case, are defined by End of line-characters. A user writing in a text box can write a novel without a single line break. It'd be easier to simply use String subset and take the first 256 characters (or however long you want it).

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 9
(4,519 Views)

nol.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 3 of 9
(4,510 Views)

An end of line will represent an end of paragraph in some application. If the text is wrapped you can use the string Get Nth Line method to determine the number of wrapped lines in your string control. Now depending available and the font used by the application where you export the content of the string control you can determine the number of line that you can allow in your string control (your string control dimension must be constant).

 

Here is a possible way to do this using the string Get Nth Line method, an event structure and the string Key Down? filter event. You can modify it to disable/enable some keys when you reached the max line number (e.g. disable the return key, enable the delete key, ...).

 

Limit string lines.png

0 Kudos
Message 4 of 9
(4,454 Views)

Try this:

nsl.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 9
(4,429 Views)

@paul_cardinale wrote:

nol.png


... only if you wire a TRUE to the "replace all?" on top, (else the answer is never more than 1).

I would also use the "line feed constant", more universal.

0 Kudos
Message 6 of 9
(4,426 Views)

Thank you.  I did forget the boolean.  However the "End of Line Constant" that I used is more universal because its output is platform dependent.  However to be truly universal:

nol.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 9
(4,407 Views)

Better yet:

nol2.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 8 of 9
(4,403 Views)

@paul_cardinale wrote:

However the "End of Line Constant" that I used is more universal because its output is platform dependent. 


The problem is that if you manually enter multi-line text into a LabVIEW string control, pressing <enter> will not insert a CRLF, just a LF (even on windows!!) so your original code will not be able to count the lines in that case.

 

I have not done any benchmarking, but "normalizing" the EOL can change the string length and thus cause memory allocations. I don't know how optimized the internal code of "Search&replace"  is if the output string is unwired, but I would probably wire the LF to both inputs to keep the string size constant. Interesting questions to explore... 😉

0 Kudos
Message 9 of 9
(4,386 Views)