Ask The Experts
The follow information is obtained from Yahoo! online community and does not express the views, opinions, or technical advice of On-Site. On-Site is not responsible for damages from use of information from Yahoo! Answers
|
Cain |
Counting characters after a character in a string in java.? |
|
Best Answer: // The source string String text = "abc"; // The string to look for in the source string String positionText = "."; // Get the location of the search string // (Keep in mind that a -1 will be returned if it // doesn't exists) int position = text.indexOf(positionText); // This will hold the length of the characters after // the search string. The whole length will return // if the search string doesn't exist. int length = 0; // Need to check the position. -1 means no occurrence // of the positionText value. if (position > -1) { // Remember that the position is based on a zero based // array so need to add 1 to it for length length = text.length() - position + 1; } else { // No search string so return the whole length length = text.length(); } View more answers to this question. |
|




