Copy Paste Code

poorvadate

poorvadate

@poorvadate-rUW4Cf Oct 19, 2024
suppose i have following text in my text file:
the apple is red in color.
and the sun shines in the morning.
now from the above 2 lines suppose i have to select following words in the sequence:
1 . the sun
2 . is red in color
3 . and
4 . shines in the morning.

and paste them to get the sentence:
the sun is red in color and shines in the morning.
what we do is for every word i''l have to first select it and then type ctrl+c to copy and ctrl+v to paste. then again for next selection i do the same copy paste operations.
so now can i write some code which will allow me to select multiple words from different sentences and and copy paste them all together to get a new sentence containing these words in the sequence in which i selected the words while copying?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Feb 5, 2011

    I am not sure .but i think you can create some Macro using MS word for this purpose
  • slashfear

    slashfear

    @slashfear-tSWzpz Feb 7, 2011

    Hi Poovadate,

    I guess if you know perl or any other language which supports regular expressions like python or java we can do this task in a simple way!! (I am not good in java 😔 ) I am going to show you how to do it perl (sorry for the shabby code was in a hurry to write it......)

    Lets say the content is in the file named "samp.txt",

    the apple is red in color
    and the sun shines in the morning
    
    The program to manipulate it would be something like this,

    open(FILE, "samp.txt");
    
    while(<FILE>)
    {
    if($_ =~ s/apple/sun/ || $_ =~ s/the sun//)
    {
    print $_ . "\n";
    
    }
    
    }
    
    
    Basically i am using substitution regular expression to substitute apple with sun and the sun with nothing 😀 simple...........!! (Hope this is what you wanted!!)


    If you have any questions, please feel free to ask back.....


    -Arvind
  • Deepika Bansal

    Deepika Bansal

    @deepika-jf1ysv Feb 8, 2011

    Great idea of using programming for this concept. Adding more features, we can make it generic as well.