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
 Forum for Origin C
 Pasting and interpreting clipboard text
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 05/02/2006 :  11:53:47 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5 SR6
Operating System: Win2000

Hi,

I want to copy some data to the clipboard then use indiviual rows eg#

ID1
ID2
.
.
IDn

The problem is that I can't figure how to interpret when one row ends and another begins (ie substrings?). I have to create a temporary worksheet, use GetClipboardText and then PasteData with the new worksheet. Read the individual rows then delete the temp worksheet.

Is there a slicker way - vectors/char arrays/anyting..?

Cheers,

pete

Mike Buess

USA
3037 Posts

Posted - 05/02/2006 :  1:38:31 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Pete,

There may be slicker methods but the code below works for standard line ending character sequences (\r\n, \r or \n). Of course it will fail if clipboard text contains the '|' character.

string str;
if( !GetClipboardText( str ) ) return;
str.Replace("\r\n","|");
str.Replace('\r','|');
str.Replace('\n','|');
for(int i=0;i<str.GetNumTokens('|');i++)
{
printf("line %d: %s\n",i+1,str.GetToken(i,'|'));
}

Mike Buess
Origin WebRing Member
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 05/02/2006 :  7:43:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
How about this approach ..
 
bool ClipBoardToStringArray(StringArray &strClipBoard)
{
string strCBtext;
if(GetClipboardText(strCBtext)==true)
{
strClipBoard.SetSize(0);
string strLine, strDelimiter="\r\n";
int LineStart=0, LineEnd=0, ArraySize=0, i=0;
while(LineEnd!=-1)
{
LineEnd=strCBtext.Find(strDelimiter,LineStart);
if(LineEnd!=-1)
{
strLine=strCBtext.Mid(LineStart,(LineEnd-LineStart));
LineStart=LineEnd+2;
}
else
{
strLine=strCBtext.Mid(LineStart);
if(strLine.GetLength()==0)
{
continue;
}
}
ArraySize++;
strClipBoard.SetSize(ArraySize);
strClipBoard[i]=strLine;
i++;
}
return (true);
}
return (false);
}
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 05/03/2006 :  04:15:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ruthven & Mike,

Many thanks both for the assist & lesson - I think I even understand the code too. I reckon I'll adopt Ruthven's approach as it's more structured.

FYI : The code works and is used to enable the user to paste a column of text labels into a range of edit boxes on a dialog.

Cheers,

Pete



Edited by - peter.cook on 05/03/2006 04:21:19 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