More about Strings

This chapter accompanies the previous one. Read it for even more info on Strings.

11. Tail of a Substring



Tail of a Substring

Here is a fragment that computes the tail of the example string, starting with the first "a":

String example = "The sea is calm to-night." ;
String tail = example.substring( example.indexOf( "a" ) );

The way this works is:

indexOf() and substring() can be used to chop a string into useful pieces. Here is a fragment that chops an assignment statement into the part to the left of the assignment operator and the part to the right:

String statement = "value = alpha*beta + gamma;"  ;

int loc = statement.indexOf( "=" );
if ( loc !=  )
  String left = statement.substring(  0,  );
  String right = statement.substring(  + 1 );

Question 11:

Ooops. The fragment is not completed. Fill in the blanks.