Java separates invisible strings that contain ASCII code

Source: Internet
Author: User


Data rules:

1. The fields in each row are delimited by the ' \x07 ' (invisible character ^g) flag of ASCII code;

2. Each record exists as a separate line in the text file, and the ' \x06 ' (invisible character ^f) flag of the ASCII code is the end of each line;

Demand:

Read the data for each row, and then deposit it into the database.


Because the project needs, so wrote a small program to test the next. The code is as follows:

Package cn.com.syhenian.test;

public class Asciitest {public
	static void Main (string[] args) {
		String str = "201411030 Red Valley Beach sj11353";
		System.out.print (str + ">>");
		String newstr = new Asciitest (). ASCII2STR (str);
		System.out.print (NEWSTR);
		
	}
	
	Converts the invisible character \x07 to ", \x06 to"  "public
	String ascii2str (String str) {
		string newstr =";
		Char[] cs = Str.tochararray ();
		int j = 0;
		for (int i:cs) {
			if (i = = 7) {
				Newstr + = ",";
			} else if (i==6) {
				newstr = "";
			} else{
				Newstr + + Str.charat (j);
			}
			j + +;
		}
		Return Newstr
	}
}



The results of the operation are as follows:





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.