0% found this document useful (0 votes)
3 views4 pages

String Manipulation Functions Guide

Uploaded by

herosparsh24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

String Manipulation Functions Guide

Uploaded by

herosparsh24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

String Manipulations

String is a group of characters should enclosed within “”


Ex: String “Computer science”

Character Functions:
1. Character,isLetter(char ): Return type: boolean

Ex: [Link](‘D’)=true

2. [Link](char ): Return type: boolean

Ex: [Link](‘c’)=false

3. [Link](char ): Return type: boolean

Ex: [Link](‘d’)=true

4. [Link](char ): Return type: boolean

Ex: [Link](‘ ’)=true

5. [Link](char): Return type: boolean

Ex: [Link](‘E’)=true

6. [Link](char): Return type: boolean

Ex: [Link](‘A’)=false

7. [Link](char): Return type: char

Ex: [Link](‘b’)=’B’
[Link](‘D’)=’D’
[Link](‘@’)=’@’

8. [Link](char): Return type: char

ex: [Link](‘J’)=’j’
ASCII: A to Z=65 to 90
a to z=97 to 122
0 to 9= 48 to 57

String Functions:
1. length(): Return type: int

ex: String s=”Computer Science”;


int l=[Link]() will return 16

2. charAt(int): Return type: char


ex: char x= [Link](4) will return ‘u’

3. indexOf(char): Return type: int


Ex: Sring s=”MALAYALAM”
int x=[Link](‘A’) then x=1
int y=s,indexOf(4,’A’) = it returns the index of ‘A’ in the string s after 4 th index
int a=[Link](‘k’) then a=-1
4. lastIndexOf(char): Return type: int
Ex: int x=[Link](‘M’) then x=8
5. substring(int): Return type: String
Ex: String s=”Computer Science”
String a=[Link](5) then a=”ter Science”
6. substring(int, int): Return type: String
Ex: String a=[Link](5,10) then a=”ter S”
7. toUpperCase(): Return type: String

Ex: String s=”Computer”


String s1=[Link]() then s1=”COMPUTER”

8. toLowerCase(): Return type: String

Ex: String s=”LUCKNOW”


String s1=[Link]() then s1=”lucknow”

9. replace(char,char): Return type: String


Ex: String s=”MXLXYXLXM”;
Strinrg r=[Link](‘X’,’A’) then r=”MALAYALAM”
10. replace(String,String): Return type: String
Ex: String s=”The green bottle is in green bag”;
s=[Link](“green”,”red”) then s=”The red bottle is in red bag”
11. concat(String): Return type: String
Ex: String s1=”Computer”,s2=”Science”;
String r=[Link](s2) then r=”ComputerScience”
Or String r=s1+s2;
12. equals(): Return type: boolean

ex: String s1=”Lucknow”,s2=”lucknow”;


[Link](s2) will return false

13. equalsIgnoreCase(): Return type: boolean

ex: String s1=”Lucknow”,s2=”lucknow”;


[Link](s2) will return true

14. CompareTo(String): Return type: int


It compares two strings lexicographically that whether a string is bigger or smaller than other or
not.
Ex: String s1=”Computer”,sc2=”Science”;
Int x=[Link](s2) will return -16
15. trim(): Return type: String
Ex: String s=” Computer Science ”;
s=[Link]() will return “Computer Science”

16. endsWith(String): Return type: boolean

eg: String s=”Computer is fun”;


[Link](“fun”) will return true

17. startsWith(String): Return type: boolean

eg: String s=”Computer is fun”,s1=”your”;


[Link](s1) will return false
18. contains(String): Return type: boolean

eg: String p=”This is a fish”;


[Link](“is”) will return true

Conversion form string to primitive type:

Parse: It is used to convert numeric type string to corresponding numeric data type by using
Wrapper Classes.
Eg: String s=”245”;
Int x= [Link](s) will return 245

String s=”34.65”;
double a=[Link](s) will return 34.65

valueOf():

Eg: String s=”145”;


Int x= [Link](s) will return 145

Conversion from primitive data type to string:

toString():

Eg: int x=2456;


String s=[Link](x) will return “2456”

You might also like