File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes transform and change the words of a file.txt with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "transform and change the words of a file.txt with java" Watch "transform and change the words of a file.txt with java" New topic
Author

transform and change the words of a file.txt with java

Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
hello!
Can you help me please?
I have a project with java. the text is this:
from a txt file and print the contents of each row received.
Once we have the text file, for each wor, bigger than three letters, changing the distribution of the letters except the first letter and last letter.
example:

Imagine there's no heaven, it's easy if you try
No hell below us above us only sky.
Imagine all the people living for today..
.

transform:

Iganime tehre's no hveean, it's esay if you try
No hlel bolew us avbove us olny sky.
Iimnage all the pelpoe lvniig for tdaoy...


Once you change the words enter into another txt file with the same punctuation.

until now, I've done this (and I can not go ahead):


Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Hello Ro Roby,

Welcome to CodeRanch!

Please, TellTheDetails.

and I can not go ahead
What do you mean by this? Is there any compile time error in the code (by the way, its good to see that you are using code tags)? RuntimeException? Or the output is not as per expectation? What are the differences between actual output and expected output?

I hope this helps.

P.S. I can see that you are writing while loop directly inside the class. I stopped reading the code after that


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 105

Actually the while loop is inside the mixpalablas() method. It just not formatted correctly so you might missed it.


Website: Learn Java by Examples
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Yes. My bad

But still, can you please format the code properly (its difficult to track it when there are 3 closing brackets on one line or so).

And also, please TellTheDetails - exactly what is going wrong?
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
I changed the function:

how can I lock the first and last letters?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
This thread looks like somebody who is guessing. That is no way to program. You need to work out how to get the individual words out of the file. You need to work out how to reverse the inner letters, which should be quite easy. Then you need to work out how to put it all back together.

You want to do that in stages. Start by defining what a word is, and demonstrate that you can reliably identify words. Then consider the reversing later.

And welcome to the Ranch (again)
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
Thank you Campbell Ritchie...


the thread is:



and, i want to put the thread here:

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
. . . and as for the }}}, you ought to sort that out on your text editor. You should get a decent text editor (not NotePad®, I suggest jEdit Notepad2 and Notepad++), and you set up options like syntax colouring, bracket matching and automatic indentation. You also write your code backwards, which helps get the {} paired correctly.
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
sorry but i use netbean and I use the source\format command
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
I could change the words and save them in a String.
Now I have to replace these words in a file.txt
can you help me??
do I have to write the code?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

Ro Roby wrote:do I have to write the code?

Yes. We are NotACodeMill. We will help you out, but you have to do the hard work yourself.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
Rob Spoor wrote:
Yes. We are NotACodeMill. We will help you out, but you have to do the hard work yourself.

of course
I just wanted a theoretical explanation ...about to replace these words in a file.txt!!!
sorry, I badly explained.
the question: "do I have to write the code?"
was about, if I had to write the code that I have done until now!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
You can’t replace those words in a text file. You can only read them into memory and manipulate them there, and write the output back to the text file.
You are making life much to hard for yourself by messing around with tokenizers (which are legacy code and ought not to be used). You can do the whole thing in situ in a char[] array or similar.
Start by working out how you define a word. How can you identify when it starts and when it finishes? Then all you have to do is reverse it, all but its first and last letters. But you need to do it in stages. A properly designed solution will be much simpler, cleaner, shorter and easier to maintain than what you have written.
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
thanks for the advice!
I downloaded Notepad + +. sorry but if I put the code in notepad + + and after the code of this page, the result is the same. I do not see the difference. Excuse my ignorance
I making life much to hard for myselff, because i don't have experience.
I have advanced:
i changed each wor, bigger than three letters, and i changed the distribution of the letters except the first letter and last letter. but i used tokenizer (why tokenizer is "are legacy code and ought not to be used").


curiosity is: if I look in the new String its contents in another part of the program, its content is just a word
Now, now or go back and try to start without tokenizer or i start to modify the text of file.txt?
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
almost done!
I do not know why I doubled the words with a single letter ...
recommendations?
Steven Schwab
Greenhorn

Joined: May 25, 2010
Posts: 9
Your problem is here:


What happens when nuevotexto is only one character long? (Hint: nuevotexto.length() is 1, so what values will be assigned to let1 and letu?)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
I would do it completely differently.
Copy the entire String into a char[]; there is a String method which does that.
Iterate the array with two indices, maybe wordStart and wordEnd. By looking for certain characters, you can identify the start and ends of words.
You can copy that part of the array into a List, shuffle the List and copy it back
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
done!!!
thank you very very much!!!
great website!!!
Ro Roby
Greenhorn

Joined: May 10, 2012
Posts: 12
perhaps there is a small problem with the punctuation(,;.?!)...
this is my code!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: transform and change the words of a file.txt with java