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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Pasting and interpreting clipboard text

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
peter.cook Posted - 05/02/2006 : 11:53:47 AM
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

3   L A T E S T    R E P L I E S    (Newest First)
peter.cook Posted - 05/03/2006 : 04:15:52 AM
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
rlewis Posted - 05/02/2006 : 7:43:50 PM
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);
}
Mike Buess Posted - 05/02/2006 : 1:38:31 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000