first of all: in what kind of object would you like your String object to turn? since a String on itself is an object.
in order to delete the first word: go check out the api's on the indexOf( ) method and the substring( ) method.
this is about all you'll need to make your class do the trick.
stultuske
Posting Sensei
3,120 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
Hi, How do i create a class called Text
that creates an object from a string
and that deletes the first word of the text
have no idea
I was starting like
public class Text{
public static void main(String[] args)
{
String str = "this is a little text and i have to delete the first word this ";
}
}
But really i have no idea
Please any help is gratefull
Anyway, try this:
Extend existing String class in say MyString.
In MyString's constructor
- take a String as argument.
- Cut out the first word and pass on the rest to base class.hi:
you can see my code whether help you
package com.structure;
import java.util.ArrayList;
import java.util.List;
public class Text {
String statement;
List listchar = new ArrayList();
public Text(String statement) {
super();
this.statement = statement;
exchangeList();
}
..................
public static void main(String args[]) {
Text text = new Text("this is deng statement");
System.out.println(text.getStatement());
text.deleteIndex(4);
System.out.println(text.getStatement());
}
} On to your 14th post and you still haven't figured out the magic of code tags.. ?!
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
Stultuske already provided all the info needed to complete your assignment. Homework has a purpose.
deng_sen, you really need to use the code tags to make your code more readable.
Ezzaral
Posting Genius
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847