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
 concatenating 2 text columns is a worksheet
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bplinder

USA
5 Posts

Posted - 03/18/2005 :  10:42:25 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: XP

I have 3 text columns in my worksheet, data1_A, data1_B, and data1_C

I would like to concatenate the text in columns B and C and put the result in A.

Is there a simple 1 line code for this?
Or do I need to step through each row?
Also, if i need to loop through each row, is there a command to join the text in B and C together without writing to a temporary variable.

For instance this does not work

Data1_A[1]$ = data1_B[1]$ + data1_C[1]$;


Any help is appreciated.

Mike Buess

USA
3037 Posts

Posted - 03/18/2005 :  2:09:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
copy -a Data1_B Data1_A;
copy -a Data1_C Data1_A;

Mike Buess
Origin WebRing Member
Go to Top of Page

greg

USA
1379 Posts

Posted - 03/18/2005 :  2:49:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I think what user bplinder wants is to concatenate across rows, as in:

get col(A) -e end;
loop(ii,1,end) {
%A=col(A)[ii]$;
%B=%A;
%A=col(B)[ii]$;
%B=%B %A;
%A=col(C)[ii]$;
%B=%B %A;
col(A)[ii]$=%B;
}

Note that only one cell value to string --- col(name)[row]$ --- is allowed on the right side of an equation. Thus the use of %A and %B to do the actual concatenation. Also, the example puts a space between each item but other examples might use ', ' :

get col(A) -e end;
loop(ii,1,end) {
%A=col(A)[ii]$;
%B=%A;
%A=col(B)[ii]$;
%B=%B, %A;
%A=col(C)[ii]$;
%B=%B, %A;
col(A)[ii]$=%B;
}

or even pseudo multiline :

get col(A) -e end;
loop(ii,1,end) {
%A=col(A)[ii]$;
%B=%A;
%A=col(B)[ii]$;
%B=%B
%A;
%A=col(C)[ii]$;
%B=%B
%A;
col(A)[ii]$=%B;
}

This last example does not display as multiple lines in a cell
(Origin doesn't do that ... yet ;)
but when copied and pasted elsewhere would behave as such.

Go to Top of Page

bplinder

USA
5 Posts

Posted - 03/18/2005 :  5:07:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, you answered my question exactly.


"Note that only one cell value to string --- col(name)[row]$ --- is allowed on the right side of an equation."

This was what i was trying to do. Now I know i can't do that. I'll just code one of the loop structures. Thanks.



Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 11/08/2018 :  10:25:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi bplinder,

If you do such operation often, you can define a macro like following:
///////////////////////////////
def cattextds { // %1:ColRange1, %2:ColRange2
  int nr2=%2.getsize();
  for(ii=1; ii<=nr2; ii++) {
     %1[ii]$=%1[ii]$+%2[ii]$;
  }
}
range r1=col(1);
range r2=col(2);
cattextds r1 r2;
///////////////////////////////
Hope this helps.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 11/08/2018 10:26:32 AM
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