[String access] the method used to separate text strings.

Source: Internet
Author: User

[String access] the method used to separate text strings.

Q: How can I solve this problem when the length of the field column in the database is exceeded in the project?

A common solution is string access. As the name suggests, it refers to intercepting large text data by the specified length, and storing the returned result set in the new table in the cut order. Create a type field in the new table to identify the field name in the old table corresponding to the content intercepted in the new table. The fields in the old table do not directly store the enlarged text data, but store the identifier.

Here, a tool class is provided to split text strings and return the List result set for the next step.

Public class StringUtil {/*** @ Name: getContentByList * @ Description: String cutting * @ Author: Zhang (Author) * @ Version: V1.00 (Version Number) * @ Create Date: (creation date) * @ Parameters: wholecontent: passed text string; cutcount: length of the cut string * @ Return: List: a collection of cut strings, save result set */public static List <String> getContentByList (String wholecontent, int cutcount) {List <String> list = new ArrayList <String> (); // obtain the total length of the complete content string int contentlen = w Holecontent. length (); // content truncation. Compare the content length with the content length. insert if (contentlen <cutcount) {list. add (wholecontent);} // The content length exceeds the truncation length. else {// defines and initializes the content section String contentpart = ""; // define and initialize the number of intercepted paragraphs int contentround = 0; // The starting position int begincount = 0; // determine the number of intercepted paragraphs int contentcutpart = contentlen/cutcount; int contentcutparts = contentlen % cutcount; // returns the remainder. // if the remainder is 0, the content is divisible. The content length is exactly a multiple of the truncation length. If (contentcutparts = 0) {contentround = contentcutpart;} else {contentround = contentcutpart + 1;} // The content intercepted cyclically for (int I = 1; I <= contentround; I ++) {// if it is not the last part, if (I! = Contentround) {// extract content based on the truncation length contentpart = wholecontent. substring (begincount, cutcount * I);} else {// capture the last part of content contentpart = wholecontent. substring (begincount, contentlen);} // assign a value to the starting position of the next part begincount = cutcount * I; list. add (contentpart) ;}} return list ;}}

 

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.