Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

How would I go about copying and pasting?

copy paste programming java

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 Error


    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 72 posts

Posted 19 April 2015 - 12:49 PM

So I am making this awesome generator and I need to use the parts of speech (nouns, verbs, adjectives, etc.), but the tiny problem is that there are so many nouns and verbs, etc. out there. It would take me such a long time to type each one. I know it sounds lazy and it probably is, but any way to make things move along faster would probably be best. I am still still a newbie, pretty much, when it comes to coding. That being said, I appreciate any help given.


If I make a String array, I have to put my words into quotation marks. So I was thinking... Would I have to possibly create a program where I copy and paste something into the console and it gives out the words, but with beginning and end quotes added? A nudge towards this would be much appreciated. I can't even think of how I would add the quotation marks to the words (Or maybe. The brain started firing a bit). Or is there just a really simple way that I am completely unaware of?


Thanks! Any reply is appreciated!


~ Error ~

Edited by Error, 19 April 2015 - 12:53 PM.

#2 dargueta


    I chown trolls.

  • Moderator
  • 4854 posts

Posted 22 April 2015 - 05:28 PM

If you have a text editor like SciTE (or any other one that allows you to use regular expressions) you can do this easily without having to write any code. Assuming each word is on one line, just do a search and replace with


Search: ^(.*)$

Replace: "\1",


And that's it!

sudo rm -rf / && echo $'Sanitize your inputs!'

#3 charlesdavis


    CC Regular

  • Member
  • PipPipPip
  • 34 posts

Posted 05 May 2015 - 09:35 PM

You need to review and analysis of any editor all features that will be helpful for you....If i wll expalin here so it will not satisfactory results for you....

#4 PBJ


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 176 posts

Posted 07 May 2015 - 12:09 PM

Assuming you're looking for a single threaded solution, here's how I would approach the problem.

  1. Find lists of nouns, verbs, etc.
  2. Repeat for each file representing part of speech, loop
    1. File directoryLocation = new File ("/location/to/directoryOfLists");
      		File[] directoryContents = directoryLocation.listFiles();
      		if(directoryContents != null) for (File f : directoryContents) // process file as suggested below
  3. Create an HashMap, with each key representing the part of speech (verb, noun, etc) and the value being a list of values (your list of nouns, verbs, etc.)
    1. Map<String, List<String>> map = new HashMap<String, List<String>>() 
  4. Read in your file (for example nouns.txt) like so
    1. List<String> nounList = Files.readAllLines(Paths.get("/path/to/nouns.txt"));
    • Which will return all of your strings, in a format like so "noun1", "noun2", etc.
  5. Then assign your nounList to an appropriate key
    1. map.put("nouns", nounList);
  6. Your final HashMap  can be thought of as something like so:
    1. K, V --> nouns, "noun1", "noun2" ....
    2. K, V --> verbs, "verb1", "verb2" ....
    3. etc ...
  7. Then, once your lists are all completed, it's just a matter of accessing the appropriate key's value, at the correct location in your generated sentence.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download