Jabberwock Stomp
Jabberwock Stomp

Reputation: 333

Replacing an Exclamation mark at the end of a string

I am writing a program that counts song lyrics. Right now I have it programmed to delete certain characters using line.replace, for example:

String computerComma=",";

String computerPeriod=".";

String nothing="";

line=line.replace(computerComma,nothing);

line=line.replace(computerPeriod,nothing);

and this works totally fine. However, when I try

String computerExclamation="!";

line=line.replace(computerExclamation,nothing);

it messes up my entire program and many of my word counters. Does anybody know the reason behind this?

Thanks!

Upvotes: 1

Views: 4333

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122006

No. Works fine.

 public static void main(String[] args) {
         String computerExclamation="!";
         String line = "i am a String !!.";
         line=line.replace(computerExclamation,"");
         System.out.println(line);  //i am a String .

    }

Error lies some where else.

You can see here.

Upvotes: 0

Related Questions