Author |
Topic |
|
Taron
United Kingdom
12 Posts |
Posted - 05/29/2013 : 07:10:34 AM
|
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
|
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=; |
|
|
Taron
United Kingdom
12 Posts |
Posted - 06/04/2013 : 11:33:54 AM
|
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? |
|
|
greg
USA
1378 Posts |
Posted - 06/04/2013 : 1:26:37 PM
|
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=;
|
|
|
Taron
United Kingdom
12 Posts |
Posted - 06/04/2013 : 6:35:11 PM
|
Thank you so much! Very simple but effective! |
|
|
|
Topic |
|