Character Extraction Java Help

Character Extraction 

The String class provides a number of ways in which characters can be extracted from a String object. Each is examined here. Although the characters that comprise a string within a String object cannot' be indexed as if they were a character array, many of the String methods employ an index (or offset) into the string for their operation. Like arrays, the string indexes begin at zero.

char At( )

To extract a single character from a String, you can refer directly to an individual ch. character via. the char At( ) method. It has this general form: .' char char At(int where): Here, where is the index of the character that you want to obtain. The value of where must be non negative and specify a location within the string. char At( ) returns the character at the specified location. For triplex

get Chars( )

If you need to extract more than one character at a time, you can use the get Chars( ) method. It has 'this general form:' ..void get Chars(int outsource, int source End, char target[ ], int target Start Here, outsourcing specified index of the beginning 'of the sub string, and source End . specifies an index that is one past the end of the desired sub string. Thus, the sub string 'contains the characters from source star: through source-end-l. The array that will receive the characters is specified by target. The index within target at which the . illustriousness be copied is passed in target Start. Care must be taken to assure that the target array is large enough to hold the number of char ac in specified sub string. The following program demonstrates get Chars( ):  Here is the output of this program: demo.

Posted on September 17, 2014 in Staring Handling

Share the Story

About the Author

Back to Top
Share This