中易网

C#中的字符串复制函数是什么?

答案:3  悬赏:50  
解决时间 2021-01-20 09:43
C#中的字符串复制函数是什么?
最佳答案
你应该在MSDN里面找方法啊!
一、String.CopyTo 方法
将指定数目的字符从此实例中的指定位置复制到 Unicode 字符数组中的指定位置。
语法:
public void CopyTo (
int sourceIndex,
char[] destination,
int destinationIndex,
int count
)
参数
sourceIndex
此实例中的字符位置。

destination
Unicode 字符的数组。

destinationIndex
destination 中的数组元素。

count
此实例中要复制到 destination 的字符数。
示例:
using System;

public class CopyToTest {
public static void Main() {

// Embed an array of characters in a string
string strSource = "changed";
char [] destination = { 'T', 'h', 'e', ' ', 'i', 'n', 'i', 't', 'i', 'a', 'l', ' ',
'a', 'r', 'r', 'a', 'y' };

// Print the char array
Console.WriteLine( destination );

// Embed the source string in the destination string
strSource.CopyTo ( 0, destination, 4, strSource.Length );

// Print the resulting array
Console.WriteLine( destination );

strSource = "A different string";

// Embed only a section of the source string in the destination
strSource.CopyTo ( 2, destination, 3, 9 );

// Print the resulting array
Console.WriteLine( destination );
}
}

二、String.Copy 方法
创建一个与指定的 String 具有相同值的 String 的新实例。

命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)

语法
public static string Copy (
string str
)
参数
str
要复制的 String。

返回值
与 str 具有相同值的新 String。
示例:
下面的代码示例显示了由两个变量引用的两个不同的字符串,创建第一个字符串的副本,将对新字符串的引用赋给第二个变量,然后显示由两个变量引用的两个字符串,以演示两个字符串现在是相同的。
// Sample for String.Copy()
using System;

class Sample {
public static void Main() {
string str1 = "abc";
string str2 = "xyz";
Console.WriteLine("1) str1 = '{0}'", str1);
Console.WriteLine("2) str2 = '{0}'", str2);
Console.WriteLine("Copy...");
str2 = String.Copy(str1);
Console.WriteLine("3) str1 = '{0}'", str1);
Console.WriteLine("4) str2 = '{0}'", str2);
}
}


上面这些都是MSDN里的,别懒,还是把MSDN装上吧!装上后自己去看String 类的方法就OK了!
全部回答
STRCPY
Array中有个Clone方法
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
求神探高伦布国语资源
春之声琴行艺术培训中心(淮北相山区)地址有知
牟平一中今年理科高考最高分多少
我在网上买的学生迷你电磁炉,买了才几个月,突
一直有些话憋了很久想对你说。首先,如果你是
我们应该讨论明星的私人活动吗?为什么
交通事故赔偿误工费和残疾赔偿金是否互相冲突
到底是“荀季和,有义方”还是“窦燕山,有义方
怎样拍摄高调 暗调照片
快餐店搬上微商能行吗
我刚买办的桂林网上银行U盾密码错误,刚改了
读完购买上帝的小男孩给你什么启发
刚熬好的沥青用什么工具刷上墙?
济南微信朋友圈广告公司有哪家?推广多少钱?
一间陋室二眼锅灶三面透风煮出银丝千碗 下联
推荐资讯
80883636是哪家银行的电话
看到家里很乱,懒得收拾,越懒就越乱,越乱就
为什么很多情侣在根本不能确定两个人有没有未
NBA2KOL新代言人6月2日揭晓 詹皇继承者究竟是
马太福音11章20一24节基督主日讲章分享
如何在中考前15天内提高成绩
宝宝11个月最近睡觉爱打呼噜,食欲也不好,怎
一岁半的女宝宝睡觉打呼要紧吗?
如何使用干湿球湿度计?
车锁打不开 各位专家好:我的一辆奥迪A6的
万达主题酒店地址在哪,我要去那里办事
您戴几颗的手串 戴对了吗
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?