1 / 9

METHODS FOR CHARACTER EXTRACTION,STRING SEARCHING AND COMPARISON

METHODS FOR CHARACTER EXTRACTION,STRING SEARCHING AND COMPARISON. PRESENTED BY : DIPU KALITA DC2012MCA0022. INTRODUCTION.

wilmer
Télécharger la présentation

METHODS FOR CHARACTER EXTRACTION,STRING SEARCHING AND COMPARISON

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. METHODS FOR CHARACTER EXTRACTION,STRING SEARCHING AND COMPARISON PRESENTED BY : DIPU KALITA DC2012MCA0022

  2. INTRODUCTION CHARACTER EXTRACTION: The string class provides a number of ways in which characters can be extracted from a string object. Several are 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.

  3. String searching: • Many software applications use the basic string search algorithm in the implementations on most operating systems. • The popularity of Internet, the quantity of available data from different parts of the world has increased dramatically within a short time. • A string search algorithm that is language-aware has become more important. • A bitwise match that uses the u_strstr (C), UnicodeString::indexOf (C++) or String.indexOf(Java).

  4. STRING COMPARISON: String comparison can be done in 3 ways: 1.Using equals() method: equals() method compares two strings for equality. It compares the content of the strings. 2.Using ==operator method: ==operator compares two object references to check whether they refer to same instance. 3. By compare to() method: compare to() methods compares values returns an into which tells if the string compared is less than, equal to or greater than the other string. To use this function you must implement the comparable interface. Compare To() is the only function in comparable interface.

  5. DESCRIPTION CHARACTER EXTRACTION: METHOD DESCRIPTION Java - String charAt() This method returns the character located at the String's specified index. The string indexes start from zero. STRING SEARCHING: METHOD DESCRIPTION Returns the index within this string of the first occurrence of the specified substring. If it does not occur as a substring,-1 is returned. intindexOf(String str):

  6. STRING COMPARISON : METHOD DESCRIPTION There are two variants of this method. First method compares this String to another Object and second method compares two strings lexicographically. Java - String compareTo()

  7. Sample PROGRAME CHARACTEREXTRACTION: OUTPUT:Gurukul

  8. STRING SEARCHING: public class SearchStringEmp{ public static void main(String[] args) { String strOrig = "Hello readers"; intintIndex = strOrig.indexOf("Hello"); if(intIndex == - 1){ System.out.println("Hello not found"); }else{ System.out.println("Found Hello at index “ + intIndex); } } } OUTPUT: Found Hello at index is 0

  9. STRING COMPARISON: public class StringCompareEmp{ public static void main(String args[]){ String str = "Hello World"; String anotherString = "hello world"; Object objStr = str; System.out.println( str.compareTo(anotherString)); System.out.println(str.compareToIgnoreCase(anoting) ); System.out.println( str.compareTo(objStr.toString())); } } OUTPUT: -32 0 0

More Related