The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Extract specific parts from a string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Taron

United Kingdom
12 Posts

Posted - 05/29/2013 :  07:10:34 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Pro 9.0.0
Operating System: Windows 7

Hi,

I am relatively new to Labtalk and have a certain problem that I can't get solved myself.

I have files which I import to origin using the filename as the workbooks longname.
These longnames look like this XXX-187_batch_2_R8_10um_1_han1-n.txt

What I want to achieve seems quite simple to me, but I didn't find a proper way to do it in Labtalk. I just want to read out the number in between "_R8_" and "um_", which in this case would be a "10" and output is into a double or another string.

The problem is that the filenames vary in length, which means that I can't just use GetToken, as I would do it normally.

For example the filenames could also look like this:
XXX-187_batch_2_R8_Some_Random_Text_10um_1_han1-n.txt
or this
XXX-187_batch_2_R8_Some_Random_Text_5um_1_han1-n_221113.txt

Is there any easy way to extract the part of the string I need?
I hope some of the more experienced Labtalk users can help me out with this one.

Greetings,
Taron

greg

USA
1378 Posts

Posted - 05/30/2013 :  4:22:04 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The first case you described is easy.

string str1$ = "XXX-187_batch_2_R8_10um_1_han1-n.txt";
string str2$ = str1.Between("_R8_","um")$;
val = %(str2$);

but then you complicate it with random text.

There are probably several ways to approach the problem, but here is one that uses ReverseFind to find the last '_' before the 'um' and then grabs just the relevent text:

string str1$ = "XXX-187_batch_2_R8_Some_Random_Text_10um_1_han1-n.txt";
string str2$ = str1.Between("_R8_","um")$;
val = str2.ReverseFind('_');
str2$ = str2.Right(str2.GetLength()-val)$;
val = %(str2$);
val=;
Go to Top of Page

Taron

United Kingdom
12 Posts

Posted - 06/04/2013 :  11:33:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey,

sorry for answering so late, but I had a lot of stuff to do in the last days.

Perfect, thanks for the solution.
I should have specified this before, but the "8" in "XXX-187_batch_2_R8_Some_Random_Text_10um_1_han1-n.txt" is a changing character.
I tried to use ? as a wildcard, but it seems that Between doesn't support wildcards.
Sorry for not saying this in the first place, but I just forgot about it.
Do you know of any way to work around this?
Go to Top of Page

greg

USA
1378 Posts

Posted - 06/04/2013 :  1:26:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Then do not include it ..

string str1$ = "XXX-187_batch_2_R8_Some_Random_Text_10um_1_han1-n.txt";
string str2$ = str1.Between("_","um")$;
val = str2.ReverseFind('_');
str2$ = str2.Right(str2.GetLength()-val)$;
val = %(str2$);
val=;
Go to Top of Page

Taron

United Kingdom
12 Posts

Posted - 06/04/2013 :  6:35:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you so much!
Very simple but effective!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000