From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

sorting string by first character

What is the easiest way to sort strings by the first character?  I can sort by a complete string match, but what I really want to do is just sort by the first letter of character.  Is there a way to do something like a reverse concatenate?  

 

Thank you

 

Danny

Danny
0 Kudos
Message 1 of 16
(3,638 Views)

I'm not sure how the VI you attached relates to your question.

 

What does "sort by complete string match" mean?  Are you sorting a string array (which I don't see in your VI?  Or trying to match a string?

 

Please provide a VI that matches what you are trying to do, perhaps with some example data that demonstrates the before and after of what you are trying to do.

0 Kudos
Message 2 of 16
(3,636 Views)

By "sorting by first character", you mean you want to check if the first character of 'string' matches a constant?

 

Try Using the 'string subset' function to get the first character of 'string'

('string subset' = reverse concatinate.. I think that's what you meant...)

0 Kudos
Message 3 of 16
(3,600 Views)

This is one of those times where I think Regular Expressions can be of use.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 16
(3,572 Views)

I don't know if we can say what things can be of use because the original poster has failed to come back and clearly explain what he is trying to do.

0 Kudos
Message 5 of 16
(3,561 Views)

Ravensfan,  ultimately I will probably be using the read from spreadsheet file vi and read the data into an index array and then will want to sort the strings by the first character of each string and maybe process the strings in a producer consumer or state machine architecture.  I'm anything but a programmer and most of what I want to do is ouside my of simple state machine crutch I have experience with.    The example I had attached was just my attempt to make a simple test vi that I could try to read the first character of a text string I manually entered and if it matched, have it turn on an indicator. My past approach has always been to start very simple and build on it.  This was that attempt.   I'm sorry I didn't make it more clearn in my orginal post.  

 

Thank you for your response.

 

Danny

 

 

Danny
0 Kudos
Message 6 of 16
(3,543 Views)

@dannyjhu wrote:

Ravensfan,  ultimately I will probably be using the read from spreadsheet file vi and read the data into an index array and then will want to sort the strings by the first character of each string and maybe process the strings in a producer consumer or state machine architecture.


This is sounding like you will want to look into the Sort 1D Array.  I'm still not quite following what you want.  Can you give an example of an input and what you want out?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 16
(3,530 Views)

That is what I'd like to know.  How do you sort by the first character?  You want to sort by the first character but NOT the rest of the string?

0 Kudos
Message 8 of 16
(3,528 Views)

@RavensFan wrote:

That is what I'd like to know.  How do you sort by the first character?  You want to sort by the first character but NOT the rest of the string?


I guess you can group by first character, leaving string with the same first character in the index order within each group.

 

For example:

ZZY

AXD

AAF

ZEW

would sort to...

AXD

AAF

ZZY

ZEW

0 Kudos
Message 9 of 16
(3,524 Views)

Dont sort 1D array of strings sort by 1st character already? If not, then extract 1st with String subset and bundle it with the full string in a loop (the single character as 1st element), and sort the cluster array. If you need the string array back, unbundle in a 2nd loop.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 16
(3,503 Views)