0

This may seem like a bit of a strange question, but I want to make an "enter" keystroke into a string. I made a rather basic program to scan my papers (that I write for school) to find things such as prepositions at the end of a sentence or contractions I may have accidentally added. My issue is, when i put the paper into my code, it try to tokenize all the sentences at periods. When it reaches the point where I hit "enter" to move to the next line, it breaks and stops tokenizing. I thought of maybe making "enter" into a string so that i could replace it with a space, but I can't figure out how to get the effects of an "enter" into a string. Is there another way to stop the "enters" from breaking my code?

Sum up: I enter my paper into my code and the effects of hitting "enter" in the paper cause the code to err. I want to be able to enter the paper and have the code ignore the effects of the "enter."

Thanks for any help!

Nerdydude101
  • 31
  • 1
  • 1
  • 3

2 Answers2

1

In java, "enters" are considered new lines. There are several ways to combat your problem. The most simple way is to compare each index of the string with the '\n' char which denotes a new line.

Please post a sample code of your problem if the problem persists. It is easier to correct issues when someone can see exactly what you are doing.

William Callahan
  • 630
  • 7
  • 20
1

I would not look for just \n\ or \r\n as the line feed can be different from computer to computer, especially with different OS.

I would use the System Properties to get the specified line feed you need:

String enterKey = System.getProperty("line.separator");

This gets the sequence used by operating system to separate lines in text files

Ascalonian
  • 14,409
  • 18
  • 71
  • 103