LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove every nth character from a string

In Labview, I have a vi that has a control that takes in a string.

I want to remove every 66th*n-1 and 66th*n character from the string. In other words, I want to remove charcter 65, 66, 131, 132, 197, 198 etc. from the string and return the new string that has the characters 1-66, 67-130, 133-196, etc.

The 66th*n character is always \n.

What is the best way to proceed?
0 Kudos
Message 1 of 7
(4,889 Views)
If I understand what you are wanting correctly, you have a string with linefeeds in it and wish to remove them.  I assume the \n is no where else in the string.  If so, in the string palette (LV8+ at least) there is a "search and replace pattern" function.  You can search for \n and replace with nothing OR replace with a space or whatever it is that you want.  If there are other linefeeds that you are not interested in replacing, You can set the function to start searching farther in the string.  Additionally, this function can remove/replace ALL linefeeds in the input string.
Hope this helps.

Paul
0 Kudos
Message 2 of 7
(4,871 Views)
Hi elliott,

this is the general case (when the 65th char is different every line):

Remember: when the string gets (very) big you may run into memory problems because of building array of strings and converting back to single string.

Message Edited by GerdW on 05-31-2007 02:11 PM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(4,870 Views)

GerdW,

Just a thought:  It would be helpful for the reader to build the vi, if you also include the labels of functions used, while posting a snapshot of a proposed solution

Also, I believe that 'elliott' wanted to remove those characters and the new string would be without characters at these locations

Message Edited by devchander on 05-31-2007 07:25 AM

0 Kudos
Message 4 of 7
(4,861 Views)
Hi devchander,

ok, I will include function names next time.

But from elliot's post I think he meant "remove chars" (as described in the last sentence: chars 1-64, 67-130, 133...) and not "clearing chars to zero (or whatever)".
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(4,854 Views)

Elliot,

Is  this understanding of mine, correct??

You want to remove every (66*n)-1 and (66*n)th character from a string

The resulting string must contain all other characters, except these

If Yes, see if this vi works for you

Regards,

Dev

 

0 Kudos
Message 6 of 7
(4,815 Views)
Sometimes, it is easier to work with byte arrays. Here are two simple example. See if they work for you.
 
(For simplicity, we assume that the original string size is an integer multiple of 66).
 
LabVIEW 8.0.
 
Loop version: Re-use the input array for the output, trim at the end.
Noloop version: Reshape array to Nx66 array, take Nx64 subset, reshape to 1D. 
 

Message Edited by altenbach on 06-01-2007 12:03 AM

0 Kudos
Message 7 of 7
(4,805 Views)