C#中如何利用string.copyto方法将字符串存入字符数组

您所在的位置:网站首页 怎么输入一个字符数组 C#中如何利用string.copyto方法将字符串存入字符数组

C#中如何利用string.copyto方法将字符串存入字符数组

2023-09-24 13:20| 来源: 网络整理| 查看: 265

题目如下

编写一个分类统计字符个数的程序,统计输入的字符串中数字、字母和其他字符的个数

要求:利用String.CopyTo方法将字符串存入字符数组,再使用foreach和if语句遍历并判断数组中的每个字符以进行相应处理;除数为零要提示错误;利用只读的Textbox输出运算结果。

重点来了!!!

如何利用string.copyto方法将字符串存入字符数组?

string.copyto方法有是什么?如何使用?参数有哪些?

一、语法定义(C# System.String.CopyTo 方法 的用法)

public void CopyTo( int sourceIndex, char[] destination, int destinationIndex, int count )

二、参数和返回值

参数值/返回值参数类型/返回类型参数描述/返回描述sourceIndexSystem-Int32要复制的此实例中第一个字符的索引。destinationSystem-Char[]此实例中的字符所复制到的 Unicode 字符数组。destinationIndexSystem-Int32destination 中的索引,在此处开始复制操作。countSystem-Int32此实例中要复制到 destination 的字符数。返回值

void

三、提示和注释

count 字符从此实例的 sourceIndex 位置复制到 destination 的 destinationIndex 位置。

sourceIndex 和 destinationIndex 是从零开始的。

四、System.String.CopyTo 方法例子

using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string s = "abcd"; char[] c = new char[10]; s.CopyTo(0, c, 0, s.Length); for(int i=0;i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3