CrazyEngineers
  • Copy Paste Code

    poorvadate

    poorvadate

    @poorvadate-rUW4Cf
    Updated: Oct 19, 2024
    Views: 1.0K
    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?
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberFeb 5, 2011

    I am not sure .but i think you can create some Macro using MS word for this purpose
    Are you sure? This action cannot be undone.
    Cancel
  • slashfear

    MemberFeb 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
    Are you sure? This action cannot be undone.
    Cancel
  • Deepika Bansal

    MemberFeb 8, 2011

    Great idea of using programming for this concept. Adding more features, we can make it generic as well.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register