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
 Find string value in column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

LC_

42 Posts

Posted - 05/21/2015 :  07:23:31 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2015 SR1
Operating System: Win 7

Hi, I need to find a string in a column of string data. I tried to use vfind, but if I search for a string it will always return me a vector with all the row numbers in the column. Example is below (extract from actual function).

Thanks in advance

function name_conversion (string refName)
{
//finds row corresponding to refName
dataset found_rows;
vfind ix:=col(1) value:=refName$ ox:=found_rows;
//if refName$ is a string, vfind will return all the rows in col(1) and the correct row if refName$ is numeric
return 0;
}

string str_test1$ = name_conversion("blablabla")$;

Castiel

343 Posts

Posted - 05/21/2015 :  09:06:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Documentation says "value" must be a double precision floating point number....vfind is not for strings.

妾+   午旦  妹罕妾  妾伊    用仇  妾/     岫ㄞ
 妾京用 仍巨  件 侈   件戶' 甘岫平   /欠  白岫妹
   併             艮          岫  奈 白   岫
                              岫
Go to Top of Page

AmandaLu

439 Posts

Posted - 05/26/2015 :  05:21:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi LC,

Castiel is right. vfind is used to find numeric values. To find string, please try wxt:

http://www.originlab.com/doc/X-Function/ref/wxt

Thanks,
Amanda
OriginLab Technical Service
Go to Top of Page

LC_

42 Posts

Posted - 05/26/2015 :  06:48:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Amanda! Thanks very much for your answer. Using wxt for this purpose was not very obvious to me.
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 05/27/2015 :  4:26:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It is unfortunate that Origin does not have a basic string search function for a column, so I have written it as follows:

function int sfind(string str, range cc)
{
	int nRows = cc.nRows;
	dataset tmp = data(1, nRows);
	string str1$=lookup(str$, cc, tmp)$;
	int nn = %(str1$);
	return nn;
}


To use it, you have to define a range variable, like

range aa=col(1);
v1=sfind("abc",aa);
v1=;


CP
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