Showing results for 
Search instead for 
Did you mean: 
Reply

Extract Substring from String

Solved!
Go to Solution

Extract Substring from String

For the life of me I cannot find a function that extracts a substring from an existing string.  The closest I could find was SearchSplit String and Replace Substring, but neither of them do what I want.

 

This is what I want to do:

 

Assuming a string "Test String", the letters are in positions as follows:

 

T e s t _ S t r i n g
0 1 2 3 4 5 6 7 8 9 10

 

Now extact substring from offset 5 to position 7 (Length 3):

 

Substring = S t r

            5 6 7

 

In Java, for example, you can easily do this using the code below:

 

String str = "Test String";

String subString = str.substring(5,7);

 

Is there no simple function to do this in LabVIEW?  If not, what's the easiest way to do this?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 1 of 7 (893 Views)
Reply
0 Kudos
Solution
Accepted by topic author MrHappyAsthma
‎08-27-2015 06:09 PM

Re: Extract Substring from String

Use String Subset with index 5 and length 3.

Message 2 of 7 (876 Views)

Re: Extract Substring from String

Oh perfect.  Thank you.  I was hunting through the Strings Pallette and that one didn't catch my eye.  What the world is a "string subset"?  Couldn't they just give the String Functions normal String Function names like other languages? Smiley Tongue

 

Either way, thanks!  That did what I was looking for!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 3 of 7 (872 Views)
Reply
0 Kudos

Re: Extract Substring from String

Hello all,

It is very strange that i use the function StrSubset('Hello World',3,5) and it prompts an error :

Unknown symbol on line 1 column 1: StrSubset

Anyone has an idea on it?

Thanks in advance.

 

0 Kudos
Message 4 of 7 (144 Views)
Reply
0 Kudos

Re: Extract Substring from String


linaniaina wrote:

Hello all,

It is very strange that i use the function StrSubset('Hello World',3,5) and it prompts an error :

Unknown symbol on line 1 column 1: StrSubset

Anyone has an idea on it?

Thanks in advance.

 


You probably should have started a new thread. Solved threads usually don't see a lot of new activity. Also it's not clear where you're finding this function or which function you are using. The way you wrote it out, it looks like it's not LabVIEW so you may have meant to post this to the LabWindows/CVI board?

0 Kudos
Message 5 of 7 (132 Views)
Reply
0 Kudos

Re: Extract Substring from String

Dear Taki1999,

Yes, i understand that it is a solved post but the solution seems not working on my side.

I tested the code in the Mathscript tool of Labview 12 and i found the syntax of the function StrSubset() on one Labview pdf document after a long hour of search.

If you can only give me the right syntax please so we can close definitely the topic.

0 Kudos
Message 6 of 7 (103 Views)
Reply
0 Kudos

Re: Extract Substring from String

You should be using this outside of the Matscript node.  You are looking for this function:  http://zone.ni.com/reference/en-XX/help/371361H-01/glang/string_subset/ .  Easiest way to get to it is go to your block diagram, press Ctrl+Space_bar to get quickdrop, type in "String Subset", and you will find that function.  Wire in your string and arguments and you should get your desired results.

0 Kudos
Message 7 of 7 (88 Views)
Reply
0 Kudos