simulates the Trim method in a string to remove spaces at both ends of a string
public class Stingtrimdemo {//simulates a trim method, removing a space on either side of a string ", public static void main (string[] args) {//TODO auto-generated met Hod stubstring s = " my java "; System.out.println ("The string +++:[before the space is not removed" +s+ "]");//The method of calling the custom Go space Mytrim (s);} private static void Mytrim (String s) { //TODO auto-generated method stub int start = 0,end = S.length () -1;
while (Start<=end&&s.charat (start) = = ") start++; while (Start<=end&&s.charat (end) = = ") end--; S=s.substring (start,end+1); System.out.println ("Remove the string after the front and back space [" +s+ "]"); }}
To Run the program:
Dark Horse programmer--java--simulates the trim method in a string to remove spaces at both ends of a string