go to previous page   go to home page   go to next page

Answer:

0


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:

Computing a Substring

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.


go to previous page   go to home page   go to next page