Java/JS split Java/JS flip

Source: Internet
Author: User

JS segmentation:

VaR S = 'I am 1234567890 I am 1234567890 I am 1234567890 I am 1234567890 I am 1234567890 ',
Reg =/. {4}/g,
Rs = S. Match (REG );
Rs. Push (S. substring (Rs. Join (''). Length ));
Alert (RS)

Java segmentation:

Public static string [] Split (string MSG, int num ){
Num = num + 1;
Int Len = MSG. Length ();
If (LEN <= num)
Return New String [] {MSG };
Int COUNT = Len/(Num-1 );
Count + = Len> (Num-1) * count? 1: 0; // It should be worth noting
String [] result = new string [count];
Int Pos = 0;
Int splitlen = num-1;
For (INT I = 0; I <count; I ++ ){
If (I = count-1)
Splitlen = len-Pos;
Result [I] = msg. substring (Pos, POS + splitlen );
Pos + = splitlen;
}
Return result;
}

 

JS flip:

VaR teststring = "1234567 in love with 8 .. ";
VaR teststring = teststring. Split (""). Reverse (). Join ("");

Java flip

Public void convertstr (string Str ){
// Set string
The object is converted to a variable stringbuffer class object.

// Call the reverse () method of the stringbuffer class to implement inversion.
String strreverse = new
Stringbuffer (STR). Reverse (). tostring ();

System. Out. println (strreverse );

}

 

 

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.