Read the length of a Chinese string and intercept characters in a Chinese string by length

Source: Internet
Author: User
Public   Int Length ( String Strlen)
{
Int L, T, C;
Int I;
L = Strlen. length;
T = L;
For (I = 0 ; I < L; I ++ )
{
C = ( Int ) Strlen [I];
If (C < 0 )
{
C = C + 65536 ;
}
If (C > 255 )
{
T = T + 1 ;
}
}
Return T;
}

Public   String Substring ( String Strvalue, Int Startindex, Int Length)
{
Int Istarttemp =   0 ;
Int Itemp =   0 ;
String Returnstring =   "" ;
If (Length (strvalue) > Startindex)
{
For ( Int I = 0 ; I < Strvalue. length; I ++ )
{
Int C = ( Int ) Strvalue [I];
If (C < 0 )
C + =   65536 ;
If (C > 255 )
Itemp + =   2 ;
Else
Itemp + =   1 ;
If (Itemp > Startindex)
{
Istarttemp = I;
Break ;
}
}
}
Else
Return Returnstring;

Itemp =   0 ;
If (Length (strvalue) > (Startindex + Length ))
{
For ( Int I = Istarttemp; I < Strvalue. length; I ++ )
{
Int C = ( Int ) Strvalue [I];
If (C < 0 )
C + =   65536 ;
If (C > 255 )
Itemp + =   2 ;
Else
Itemp + =   1 ;
If (Itemp > Length)
Break ;
Else
Returnstring + = Strvalue [I]. tostring ();
}
}
Else
{
Returnstring = Strvalue. substring (istarttemp );
}
Return Returnstring;
}

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.