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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Extract specific parts from a string

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Taron 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
4   L A T E S T    R E P L I E S    (Newest First)
Taron Posted - 06/04/2013 : 6:35:11 PM
Thank you so much!
Very simple but effective!
greg 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 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 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=;

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000