Conversion between char [] and string in C #; Conversion between byte [] and string

Source: Internet
Author: User

 

(1) how to convert char [] and string in C:

String to Char []
String ss = "abcdefg ";
Char [] cc = ss. ToCharArray ();

Char [] to string
String s = new string (cc );

--------------------------------------------------
(2) how to convert byte [] and string in C:
 
Byte [] to string
Byte [] bb = Encoding. UTF8.GetBytes (ss );
String s = Encoding. UTF8.GetString (bb );
 
String to byte []
Byte [] bytes;
String str = "abc ";
System. Text. ASCIIEncoding ascill = new ASCIIEncoding ();
Bytes = ascill. GetBytes (str );

 

(3) returns an integer in reverse order, for example, 987654321 to 123456789.

// Method 1: inverted Loop
Int [] intArray = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
For (int I = intArray. Length-1; I> = 0; I --)
{
// IntArray [I];
}

// Method 2: Use the Reverse function Reverse
Int [] newArrary = intArray. Reverse (). ToArray ();

// Method 3: how to convert char [] and string in C:
String strnum= "9876543210 ";
Char [] reversed = strNum. Reverse (). ToArray ();
String newStrNum = new string (reversed );

 

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.