LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of lines in a String

Highlighted

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
(1,299 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! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 9
(1,279 Views)

nol.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 3 of 9
(1,270 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

--------------------------------------------------
The best way to say thanks is to give kudos!
0 Kudos
Message 4 of 9
(1,214 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
(1,189 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.


LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 6 of 9
(1,186 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
(1,167 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
(1,163 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... 😉


LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 9 of 9
(1,146 Views)