Handling with non-printable (control character) characters in a string

Source: Internet
Author: User
Tags printable characters

The browser cannot resolve JSON data that contains a printable string, and an error is available.

ASCII Character code Introduction: http://www.jb51.net/shouce/autoit3/source/html/appendix/ascii.htm

Processing method: To find the printable characters, and replace the printable characters can be.

The code is as follows:

	/** * @author Mr * @since 2017/1/5 * @param args/public static string Rebuildstrminusctl (string
		STR) {StringBuilder buff = new StringBuilder (); char[] arr = Str.tochararray ()//To be processed string character array char[] Ctl_arr = {(char) 0, (char) 1, (char) 2, (char) 3, (char) 4, (char) 5, (char) 6 , (char) 7, (char) 8, (char) 9, (char), (char) one, (char), (char), (char), (char), (char), (char), (char) 18, ( Char), (char), (char), (char), (char), (char), (char), (char), (char), (char), (char), (char) 30, ( Char), (char) 127,};
		Special character array list<character> ls = new arraylist<character> ();
			for (int i = 0; i < arr.length i++) {char tmp = arr[i];
				Excludes special characters for (int j = 0; J < Ctl_arr.length; J + +) {if (j+1==ctl_arr.length) {ls.add (TMP);
					}else if (Tmp==ctl_arr[j]) {ls.add (' ~ ');
				Break 
		The string for (int i = 0; i < ls.size (); i++) {Buff.append ((Character) ls.get (i));
	return buff.tostring (); }


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.