c#中将整数转化为字符串_在C#中将字符串转换为字符数组

c#中将整数转化为字符串

Given a string and we have to convert it into character array in C#.

给定一个字符串,我们必须将其转换为C#中的字符数组。

将字符串转换为char [] (Converting string to char[])

To convert a given string in char[] (character array), we use String.ToCharArray() method of String class, it is called with this string and returns a characters array, it converts characters of the string to an array of Unicode characters.

要在char [] (字符数组)中转换给定的字符串,我们使用String类的String.ToCharArray()方法 ,用此字符串调用它并返回一个字符数组,它将字符串中的字符转换为Unicode字符数组。

Example:

例:

    Input:
    string str = "Hello world!";
    
    Function call:
    char[] char_arr = str.ToCharArray();

    Output:
    char_arr: H e l l o   w o r l d !

C#使用String.ToCharArray()方法将字符串转换为字符数组的示例 (C# Example to convert string to characters array using String.ToCharArray() method)

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //string variable
            string str = "Hello world!";

            //converting string to char[]
            char[] char_arr = str.ToCharArray();

            Console.WriteLine("str: " + str);

            //printing char[]
            Console.WriteLine("char_arr...");
            foreach (char item in char_arr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            //printing types of string & char[]
            Console.WriteLine("Type of str: " + str.GetType());
            Console.WriteLine("Type of char_arr: " + char_arr.GetType());

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

输出量

str: Hello world!
char_arr...
H e l l o   w o r l d !
Type of str: System.String
Type of char_arr: System.Char[]


翻译自: https://www.includehelp.com/dot-net/convert-string-to-character-array-in-c-sharp.aspx

c#中将整数转化为字符串

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值