JAVA string functions

Source: Internet
Author: User

Don't think you can solve the problem by using. length ~

Let's briefly introduce the requirements:

I recently developed an email (Short Message) system. The short message content database contains nvarchar (200). The system uses jsp for this, now, when inserting a short message to the database, you want to determine the length of the inserted content. If the length exceeds nvarchar (200), the system prompts that the user is invalid.

These are requirements, but short messages can be used to enter letters, numbers, Chinese characters, and so on. length () is the length of a character, that is, a number, a letter, or a Chinese character is counted as one length, but the Chinese character is equivalent to two in the database, A letter or number is.

That is to say, nvarchar (100) can store 100 letters or numbers, but can only store 50 Chinese characters.

Okay, the problem arises. How can I output the length of the content obtained on the page? It is in a uniform length format (pure letter length or pure Chinese Character length ).

Hope you can give me some advice ~ Birdie thanked me here ~

Problem solved ~

You can use string. getBytes (). length. Haha ~

During the day I wrote string. getBytes ("iso8859-1"). length, but it was always wrong ~

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.