Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
import java.util.*;
class Ltrim
{
public static void main(String... S)
{
int count = 0;
char ch;
System.out.println("enter the line");
Scanner sc = new Scanner(System.in);
String Str = sc.nextLine();
for(int i=0;i<Str.length();i++)
{
ch = Str.charAt(i);
if(ch ==' ' && count == 0)
{

}
else
{
count = 1;
System.out.print(ch);
}
}
}
}
Posted

1 solution

Java
String strValue ="abcd efgh";
strValue = strValue.trim();
strValue = strValue.replaceAll(" ", "");
		
System.out.println("length " + strValue.length());
 
Share this answer
 
Comments
nikhil_kumar 2-Apr-12 16:46pm    
nice........
nikhil_kumar 2-Apr-12 16:48pm    
but i want to make Ltrim() & Rtrim() function without using any trim() function.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900