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
 Origin Forum
 Set Value and extracting numbers from strings
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

evansti4

USA
2 Posts

Posted - 05/11/2012 :  4:37:05 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.6
Operating System: XP

Hi,

I have a worksheet where the first column is a list of file names and I have been trying to use the set column value scripting area to take those file names and cut out the numbers in them and then put the numbers back together into a value. For example in column A I might have tth2p500.lvm and I would like to cut out the 2 and the 500 and put them back together in the next column as 2.500. Now I've been able to get it to work for a single number with

%a = %([Book]Worksheet,Column,Row)
%n = %[%a,>'p']
%n = %[%n,'.']
%m = %[%a,>'h']
%m = %[%m,'p']

and then in the formula area putting col(B) = %m + %n/1000.

I can't figure out how to assign %a so that it corresponds to whatever the file name is in that row not just the one I manually assign it by putting ([Book]Worksheet,1,1) for the first value. I would greatly appreciate any help.

-Tim

Hideo Fujii

USA
1582 Posts

Posted - 05/11/2012 :  4:57:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tim,

For ii-th row, the assignment %a=col(1)[ii]$; should work to set %a.
Thus, maybe your code would look like:
for(ii=1; ii<=wks.maxRows; ii++) {
  %a=col(1)[ii]$;
  %n = %[%a,>'p'];
  %n = %[%n,'.'];
  %m = %[%a,>'h'];
  %m = %[%m,'p'];
  col(B)[ii]= %m + %n/1000.;
}
--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 05/11/2012 5:00:00 PM
Go to Top of Page

easwar

USA
1964 Posts

Posted - 05/11/2012 :  6:08:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Version 8.x has better string processing capability in script, and the code could be written the following way using new methods, and perhaps is more "readable" than the old % notation.

Easwar
OriginLab


range rin=1, rout=2;
string str$, str1$, str2$;
for(int irow=1; irow<=rin.GetSize(); irow++)
{
   str$=rin[irow]$;
   str1$=str.Between("h","p")$;
   str2$=str.Between("p",".")$;
   rout[irow]=%(str1$) + %(str2$)/1000;
}  
Go to Top of Page

evansti4

USA
2 Posts

Posted - 05/11/2012 :  6:17:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you so much, Hideo that worked perfectly. And Easwar, that is much more readable. We just upgraded from 7 so I'll have to brush up on new notation and syntax. Thanks again, both of you.
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 05/14/2012 :  09:33:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi evansti4,

FYI, here is a list of string functions available in ver. 8.0(SR6) or later:

http://wiki.originlab.com/~originla/ltwiki/index.php?title=Category:String_and_Characters_%28Labtalk%29

--Hideo Fujii
OriginLab
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