string origin="programmer";Console.WriteLine("origin equals:"+origin);origin[0]='A';Console.WriteLine("After change:"+origin);visual studio.net 2003 提示: D:\dotnet\TestChangeString\Class1.cs(24): Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
Console.WriteLine("After change:"+strAfterChange);//ArogrammerNotice : substring method is difference from its in java:public String substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. 在java 里这个方法取的是下标索引int beginIndex,int endIndex而C#: [C#] public string Substring( int startIndex, int length) 上面如果写成: string strAfterChange='A'+origin.Substring(1,origin.Length); 在java里可以,可是如果在C#将抛出ArgumentOutOfRangeException
D:\dotnet\TestChangeString\Class1.cs(24): Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
string strAfterChange='A'+origin.Substring(1,origin.Length-1);
Console.WriteLine("After change:"+strAfterChange);//ArogrammerNotice : substring method is difference from its in java:public String substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. 在java 里这个方法取的是下标索引int beginIndex,int endIndex而C#:
[C#]
public string Substring(
int startIndex,
int length)
上面如果写成:
string strAfterChange='A'+origin.Substring(1,origin.Length);
在java里可以,可是如果在C#将抛出ArgumentOutOfRangeException
string str="ABCDEFG";//原字符串
int i=3;//要修改的第i个字符
string str1=str.Insert(i-1,"c");
string str2=str1.Remove(i,1);
str=str2;//修改后的字符串
char[] a=new char[10];
然后一个一个取出来存到a[i]中
再进行修改,然后再存回去结