We participated in our Advent Calendar December 19th. This will be the first post of the article, so I hope you can see it with warm eyes.
This time, I will describe the substring method
used when cutting out a character string
in Java as a memo for myself.
substring is a method to cut out a part of the character string and get it as a new character string.
Syntax: " Target string.substring (start position); "
String target = target.substring(int beginindex);
Cuts out the character on the right side from the specified index number.
String target = "Thank you";
target = target.substring(4);
System.out.println(target);
result
Please
All the characters on the right side are cut out from the specified index number and acquired as a new character string. (* Index number starts from 0.)
Syntax: " Target string.substring (start position, end position); "
String target = target.substring(int beginIndex, int endIndex);
Cuts out the characters at the specified end position from the specified start position.
String target = "Thank you";
target = target.substring(4,7);
System.out.println(target);
result
Please
The character on the right side of the index number of the start position is cut out to just before the end position and acquired as a new character string.
Note that the start position character is included, but the end position is not included and is to the front
.
Recommended Posts