LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sort a string into an array

Hi Friends,
 
Does anyone knows how to sort a string of characters(approx. 258) into an array of 4 characters?
 
Had been trying but there seems to be not direct or straight forward functions...
 
Thanx alot!!
 
Rgds,
KK
0 Kudos
Message 1 of 6
(3,505 Views)

I'm not sure what you mean by "sorting into an array of 4 chars".

If you want to convert the string into a 1D array where each four characters are an elemenet you will have to go over the string in a loop and use String Subset with the length set to 4 and the offset continuously incrementing (by multiplying the i or by using a shift register). You auto index the result of the loop and you have a 1D array. If you know the string length before the loop you can use a for loop. If you don't you will need to use a while loop.

If this didn't help you you should post an example of what kind of string you're having and what you want to get out of the function.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 2 of 6
(3,498 Views)

Yup, I meant 4 characters per element. Can you show me how do I modify this vi to display the element when I input an index?

Message Edited by kingkong on 04-18-2006 02:57 AM

0 Kudos
Message 3 of 6
(3,493 Views)
I still don't understand what you want (you didn't include an example) but the attached shows what I meant - it creates a 1D array. You can then use the array functions to manipulate that array. I would strongly recommend using the advice in my previous post.

___________________
Try to take over the world!
0 Kudos
Message 4 of 6
(3,469 Views)
No problem man... thanx for your help.
 
Currently I have a string of 260 characters(hex code) to be indexed into 4 characters in an element. Then afterwards I've got to make use of index to call out an element in the string and do some manipulation. Hence the indexing.  
 
Example: 002839473abc827839abcd.... So after ignoring the 00, index 0 = 2839, index 1 = 473a,... when called and so on for the rest of 64 indexes.  
 
But I've one more problem, because the first 2 characters of the string is not in use, any suggestions?
 
rgds,
kk

Message Edited by kingkong on 04-18-2006 08:37 PM

0 Kudos
Message 5 of 6
(3,450 Views)
Hello kk,

just cut them 🙂 (String Subset with index=2)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 6
(3,433 Views)