trim(用于去半角空格(英文))

package com.atguigu.test;

import java.lang.reflect.Field;

public class Test03 {

	public static void main(String[] args) throws Exception {
		
		// 不可变字符串
		// trim方法只能去掉半角空格
		String s = " a b ";
	//反射	
//		Class c = String.class;
//		Field f = c.getDeclaredField("value");
//		f.setAccessible(true);
//		char[] cs = (char[])f.get(s);
//		cs[2] = '1';
		
		s = s.trim();
		System.out.println( "!"+s+"!" );
		
	}
}

猜你喜欢

转载自blog.csdn.net/mingxu_W/article/details/83929829
今日推荐