copy to方法 各位高手!请教一下C#中复制字符串copy to 方法怎们用!最好能有模版!小弟不胜感激! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String str1 = "abc"; String str2 = "xyz"; str2 = String.Copy(str1); 一、String.CopyTo 方法 将指定数目的字符从此实例中的指定位置复制到 Unicode 字符数组中的指定位置。语法:public void CopyTo ( int sourceIndex, char[] destination, int destinationIndex, int count)参数sourceIndex此实例中的字符位置。 destinationUnicode 字符的数组。 destinationIndexdestination 中的数组元素。 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); }}/*This example produces the following results:1) str1 = 'abc'2) str2 = 'xyz'Copy...3) str1 = 'abc'4) str2 = 'abc'*/ 关于IEqualityComparer<T>,有没有简便的写法 有人知道网页的字体大小和系统的字体大小的转换吗? 急!!checkbox实时显示属性。。 C#如何对文件夹加密和解密 类的继承 Array.Sort的效率问题 帮小弟我看看这个上传组件 关于GDI+ 请帮我解决一下 50分 WEB 文件下载求教 如何不保存文件到服务器 直接实现读取流下载到浏览器客户端 如何通过PID查找到该进程的互斥体,并关闭,实现多开 重载运算符的问题, 用C#如何控制两个摄像头显示?
String str2 = "xyz";
str2 = String.Copy(str1);
一、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);
}
}
/*
This example produces the following results:
1) str1 = 'abc'
2) str2 = 'xyz'
Copy...
3) str1 = 'abc'
4) str2 = 'abc'
*/