This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying to make a program that corrects the punction of a paragraph, part of this is the sentances. Only the first character of the sentance is a Capital the rest r lowercase until a full stop (.) occurs, when it does tehre are two spaces and a new sentance hence a new captial letter. eg
Hello World. hello User. would become Hello world. Hello user.
I am using a string tokenizer and making a completely new string (I tried a string buffer but it just dosent have the methods i need). I am using a counter to count along the sentance eg (plz note i have made the spaces more so that can understand how i am counting) 012345678910111213012345678910 Hello world . Hello user.
Two Questions, how can i check if the charAt is 0 and change that one character to an upper case (since im putting all to lower at the begining of the process). And check for a . to add two spaces after so i can reset the counter?
Any help would be abosultly great, also I am having trouble understanding the API, does anyone know of a good site that has the classes and methods and examples of the method being described? Ty all.
I wouldn't use a StringTokenizer for this, since it is designed normally to tokenize by whole word, and what you are doing requires examining each character. So I'd use a character array and a StringBuffer. Just step through the charcter array, capitalizing the first alphabetic character after a '.', and append the character to your StringBuffer. Remember to watch for white space!
However, how you stop your program stripping out correctly capitalized proper nouns I don't know...
You could use StringTokenizer to break the paragraph into sentences rather than words. Just split on "."
I'm looking back at how I did this in REXX about 20 years ago. This editor macro reformats a paragraph within margins and optionally capitalizes the first word of each sentence.
I'm looking for punctuation on the end of a word. If I find :;.!? I insert an extra space after the word. If I find .!? I capitalize the next word.
There is a lot of other stuff going on here. We have left and right margin for the first line of a paragraph and all other lines, allowing indent, undent, etc. Rj is a boolean dealing with right justification - adding extra spaces to pad each line out to the right margin.
Boy, I hope my code has gotten a little easier to read in 20 years!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ok I have fixed some but am still having problems, I am trying to limit the amount of spaces to 1 except after a . where it is two spaces. Here is my current code
As you can see atm I am using a spaceCounter, however it is still not limiting the spaces in between words (my new fav passtime of hitting head against keyboard) any help would be great ty all for the help so far and ty for any future help.
Joined: Jan 29, 2003
I think you can simplify a great deal. Just deal wtih space delimited words:
Joined: Mar 25, 2004
But wont that still put in the normal spaces? given that tokenizer serpates words normaly? or are you saying add an additonal space after punction? I am trying to limit the amount of spaces atm to one between. ty for help.
You'll learn a lot more by reading the Javadoc, or trying it out yourself. In this case, if you read you'll find that with StringTokenizer (when used normally), a sequence of separator characters (spaces in your case) will be treated as one separator, so you'll only get the words themselves, with no spaces.
I think Stan's given you a solid, simple approach to this problem...see what you can do with it.
-Tim [ May 26, 2004: Message edited by: Tim West ]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com