LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How Do I Trim A string from the leading spaces?


i.e " XXX " ==> "XXX"
Thank you How Do I Trim A string from the leading spaces?
i.e " XXX " ==> "XXX"
Thank you
0 Kudos
Message 1 of 10
(4,989 Views)
Use the "Search and Replace String" function from the string palette to search the string for spaces and replace them with nothing. Make sure you set the "replace all?" input to true, or else it will just replace the first space. The output will be your string without spaces.

Brian
0 Kudos
Message 2 of 10
(4,989 Views)
thanks Brian, But can I use Search and Replace String function to replace linefeed, carriage return, and spaces at the same time? I tried to do [\s\n\f] and it didn't work. It only work either. Do i need to use Search and Replace String three times to solve that problem? Answer is greatly appreciated...Bassam
0 Kudos
Message 4 of 10
(4,988 Views)
I don't think that you can do that. When you put \s\n\f in as your search string then it looks for space, newline, and form feed to happen consecutively in that order. If you expect any of the parameters to happen together then you can combine those into one search and replace, otherwise I think you have to use seperate instances of Search and Replace

Brian
0 Kudos
Message 5 of 10
(4,988 Views)
A brute force approach would be to use a "while" loop to go through the
string character by character checking each character using the "Whitespace"
or "Lexical Class" comparison functions. When you hit the first real
character in the string, you terminate the while loop and use the iteration
counter to split the heading whitespace from the rest of the string.

If you want to eliminate all whitespace, then simply build a new string in a
shift register, and as you test each character from the original string
either append it to the new string or not, depending on what it is. However,
using "search and replace" three times may execute faster if you only want
to zap those three characters, even though it would initially appear less
efficient.

Bassam
@no.email> wrote in message
news:506500000005000000221F0000-984882144000@quiq.com...
> thanks Brian, But can I use Search and Replace String function to
> replace linefeed, carriage return, and spaces at the same time? I
> tried to do [\s\n\f] and it didn't work. It only work either. Do i
> need to use Search and Replace String three times to solve that
> problem? Answer is greatly appreciated...Bassam
0 Kudos
Message 6 of 10
(4,988 Views)
On Mon, 26 Mar 2001 09:29:46 -0800 (PST), Bassam wrote:

>thanks Brian, But can I use Search and Replace String function to
>replace linefeed, carriage return, and spaces at the same time? I
>tried to do [\s\n\f] and it didn't work. It only work either. Do i
>need to use Search and Replace String three times to solve that
>problem? Answer is greatly appreciated...Bassam

Did you remember to set the string constant to show codes?

--
Rolf
0 Kudos
Message 7 of 10
(4,988 Views)
What exactly needs to be wired to the "search string" and "replace string" inputs to the block in order to search and replace all spaces. I have tried wiring [\s] to the search string input and wiring nothing to the replace string input. Is this correct?

Any help is appreciated.

Thanks
0 Kudos
Message 9 of 10
(4,988 Views)
If you know what 'XXX' is then use match pattern vi under the string palette. Enter the text 'XXX' as the regular expression and take your output off the match substring output.

If you don't know what the text is you can remove the leading spaces by wiring "[\s]*" into the regular expression (without quotes). This tells it to look for 0 or more instances of the space character. Take you output off of the after substring output.

The wildcards will allow you to make some very tricky searches quite easy.

Jared
0 Kudos
Message 3 of 10
(4,988 Views)
On Mon, 26 Mar 2001 08:32:27 -0800 (PST), Bassam wrote:

>How Do I Trim A string from the leading spaces?
>i.e " XXX " ==> "XXX"
>Thank you

It seems that you want to trim leading and trailing spaces.

If the string contains one word then you have two solutions.

Either
use one 'Match Pattern' function with regular expression
set to "[^ ]+"
or
use one 'Scan From string' function with format string
set to "%s"

If you want to remove leading and trailing spaces and keep spaces
between words it seems that you need two 'Match Pattern'

Use "^[\s\r\n]*" as 'regular expression' for the first Match pattern.
Wire 'after substring' from the first 'Match Pattern' to the 'string'
input of the second 'Match Pattern'
Use "[\s\r\n]*$" as the 'reg
ular expression' for the second 'Match
Pattern'.
You should now have your string in 'before substring' output of the
second 'Match Pattern'.

Remember to set the string constants as "'\' codes display".
Message 8 of 10
(4,988 Views)
Bassam;

In the Openg.org web page there is a vi that do exactly that and is called "Trim Whitespace.vi"

Regards;

Enrique
www.vartortech.com
0 Kudos
Message 10 of 10
(4,988 Views)