• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking a string

 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use regex for this.
 
Ravi Nikam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Campbell Ritchie , I get the point.
Will not be repeated
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you're not annoyed with me; thank you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic