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
 String manipulation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

illysam

Canada
13 Posts

Posted - 02/23/2004 :  10:41:45 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have a string of the following format:

token1 token2 token3 token4 ...

What's the best way to delete a single token from that string? The problem is that only the token text is known while the position of the token is variable.

Thanks, Rolf.

Mike Buess

USA
3037 Posts

Posted - 02/23/2004 :  11:45:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rolf,

One way is to examine each token like this...
%R=string;
%S=token_to_delete;
%T="";
for(i=1; i>0; i++) {
%A=%[%R,#i];
if( %A=="" ) break;
if( "%A"!="%S" ) %T=%T %A;
};

...There is a shorter way to do it but I can't to get the expression to appear in a forum message. Email me if you're interested.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 02/23/2004 11:47:01 AM
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 02/23/2004 :  12:05:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you have Origin 7.0 or higher you can also try the OriginC option. The following (or something like it) should work

 
bool delete_token (string &InputString, string TokenString)
{
/*
Deletes the string "TokenString" from the string "InputString"
*/
string LocalCopy="";
int i=0;
while (i<InputString.GetNumTokens())
{
string strToken=InputString.GetToken(i);
if (strToken.Compare(TokenString)!=0)
{
LocalCopy+=strToken;
LocalCopy+=" ";
}
i++;
}
InputString=LocalCopy;
return (true);
}
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 02/25/2004 :  10:34:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rolf.

You can also use a simple substring notation:
%[%A," token"] %[%A,>"token "],

e.g.,
  %a="abc bcd cde";
  type %[%A," bcd"] %[%A,>"bcd "];
  abc cde

Though it seems that this works only when the search token is a literal.

Hiedo 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