Dark Horse programmer--java--simulates the trim method in a string to remove spaces at both ends of a string

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.