Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

a problem with the CUT command

  Asked By: Karina    Date: Nov 02    Category: Java    Views: 847
  

I'm trying to put a CUT command in operation and I'm having problems. The
CUT works and the PASTE works too but it takes the words in the first line
of my file, if the word in the second line is identical. For example if I
use these 3 lines:

The brown cow was very sad
The brown cow was very sad
The brown cow was very sad

and let's say that I want to CUT the "was very" in the middle line then the
CUT takes the first instance on line 1 away.

Here's the code that I am using:

storeText = text.getSelectedText();
int cutindex = text.getText().indexOf(storeText);
text.replaceRange("", cutindex, cutindex + storeText.length());

Any ideas?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Orville Rodriguez     Answered On: Nov 02

The method indexOf(storeText) returns the first occurrence of the
string. Try using the JTextComponent methods cut() and paste() or
getSelectionStart()

 
Answer #2    Answered By: Bonifaco Garcia     Answered On: Nov 02


The function indexOf(storeText) Returns the index within this string
of the first occurrence of the specified substring.... try using the
JTextComponent function cut() and paste() or getSelectionStart()

 
Didn't find what you were looking for? Find more on a problem with the CUT command Or get search suggestion and latest updates.




Tagged: