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.
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.
07-17-2013 08:03 PM
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
07-17-2013 08:17 PM
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.
07-18-2013 04:57 AM
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...)
07-18-2013 12:12 PM - edited 07-18-2013 12:13 PM
This is one of those times where I think Regular Expressions can be of use.
07-18-2013 12:35 PM
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.
07-18-2013 04:44 PM
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
07-18-2013 05:49 PM
@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?
07-18-2013 06:08 PM
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?
07-18-2013 07:14 PM
@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
07-18-2013 09:27 PM
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