Sapt 5 SECTIUNEA 3 Lectia 3 - String Processing
Sapt 5 SECTIUNEA 3 Lectia 3 - String Processing
String Processing
Overview
Strings
Parsing a String
1. Increment through the for loop until you find the character or
Substring where you wish to parse it.
2. Store the parsed components.
3. Update the String.
4. Manipulate the parsed components as desired.
StringBuilder
StringBuilder Methods
StringBuilder String
Changeable Immutable
Regular Expressions
Regular expressions:
• Are part of the java.util.regex package, thus any time
regular expressions are used in your program you must
import this package.
• Syntax is different than what you are used to but allows
for quicker, easier searching, parsing, and replacing of
characters in a String.
String.matches(String regex)
Square Brackets
This code returns true if word begins with any lower case
letter and ends in “anana”. To include upper case
characters we would write:
return word.matches(“[a-zA-Z]anana”);
The Dot
Repetition Operators
Repetition
Definition Sample Code Code Meaning
Operator
Returns true if str is
{x} X occurrences return str.matches(“A{7}”);
a sequence of 7 A's.
Returns true if str is
Between x & y
{x,y} return str.matches(“A{7,9}”); a sequence of 7, 8,
occurrences
or 9 A's.
Returns true if str is
X or more
{x,} Return str.matches(“A{5,}”); a sequence of 5 or
occurrences
more A's.
Pattern
Matcher
Matcher.find()
replaceAll Method
Terminology
Terminology
Summary