wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Checking a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Checking a string" Watch "Checking a string" New topic
Author

Checking a string

Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
hey,

I am trying to go through a string and check if the string STARTS with "409.04" at the moment i can inly check if it contains it. here is my code:

String rebateCode = clcc.getRebateCode();
String num = "409.04";

if (rebateCode.contains(num)) {

// rest of code
}

How would i check if the string start with num?

Thanks


Potrzeba jest matka wynalazków
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

You can use regex for this.


My Blog SCJP 5 SCWCD 5
Ravi Nikam
Greenhorn

Joined: Sep 28, 2007
Posts: 6
Use String's ... method.

[deleted. CR]

[ December 03, 2008: Message edited by: Ravi Nikam ]
[ December 03, 2008: Message edited by: Campbell Ritchie ]
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

You can use ,
rebateCode....("404");

or
rebateCode....("404",10); //2nd argument specific from which index

[edit]Delete answer. CR[/edit]
[ December 03, 2008: Message edited by: Campbell Ritchie ]

SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
If you go through the String class and read the list of methods, you will find exactly what you are looking for.
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Thanks guys
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
[Pull Rank]
Please, Ravi, and James, don't be annoyed with me.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
That is what it says on the entry page to the beginner's forum. It is much better to give a hint, which Maja Grajewska will find, and remember, than to give a simple answer straight off.

I have thought it right to delete parts of the posts because the answers would have taught her less than finding the solution herself.

You might disagree, but I am going to pull rank, and please don't be annoyed with me.
[/Pull Rank]
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Ok Campbell Ritchie , I get the point.
Will not be repeated
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
I'm glad you're not annoyed with me; thank you.
 
 
subject: Checking a string
 
Similar Threads
Java Rule Round-Up
My Array
Query Regarding String ???
problem in retreiving value
Simple program: NEED HELP!!