The Artima Developer Community
Sponsored Link

Java Answers Forum
double method calls

2 replies on 1 page. Most recent reply: Mar 14, 2006 11:06 PM by nabakumar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
joe auerbach

Posts: 14
Nickname: anivair
Registered: Feb, 2006

double method calls Posted: Mar 14, 2006 5:57 PM
Reply to this message Reply
Advertisement
Say (because it's the case) I want to search a string for a specific phrase. As of now, we'll call it "cube".

I can do this:
stringName.findInLine("cube");

Yes? Fine I hope.

ABut say I need to respond the same to cube, Cube, CubE and CUBE?

Can I:
stringName.findInLine.ignoreCase("cube");


eh?

if not, how can I do this? Maybe before I do the search I can do this:
stringName.toLowerCase;
stringname.findInLine("cube");


Which way is more correct, if either are correct? My syntax may be a bit off, but hopefully I got my point across.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: double method calls Posted: Mar 14, 2006 10:26 PM
Reply to this message Reply
You can't do this of course.
findInLine is a method.

toLowerCase is a method which returns the string in lower case. The original String is NOT changed.

1. You didn't call it as a method
2. Even If you would have, it woudln't work, because you don't do anything with the result.
3. findInLine does not exist in the String datatype. Use indexOf instead (read the API for a complete description.
)

nabakumar

Posts: 23
Nickname: nkmeitei
Registered: Jun, 2005

Re: double method calls Posted: Mar 14, 2006 11:06 PM
Reply to this message Reply
As mentioned by matt,
you may use str.toLowerCase().indexOf("cube") to check whether the returned value is -1 or not.

Flat View: This topic has 2 replies on 1 page
Topic: parse a string into an array Previous Topic   Next Topic Topic: Is this task hard for a beginner to accomplish in 1 day?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use