String.Insert 方法 [C#]请参见 String 类 | String 成员 | System 命名空间 | Int32 | Concat | CopyTo | Insert | Join | Remove | Replace | Split | Substring | Trim 要求 平台: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family 语言 C#C++JScriptVisual Basic全部显示 在此实例中的指定索引位置插入一个指定的 String 实例。[Visual Basic] <Serializable> Public Function Insert( _ ByVal startIndex As Integer, _ ByVal value As String _ ) As String [C#] [Serializable] public string Insert( int startIndex, string value ); [C++] [Serializable] public: String* Insert( int startIndex, String* value ); [JScript] public Serializable function Insert( startIndex : int, value : String ) : String; 参数 startIndex 此插入的索引位置。 value 要插入的 String。 返回值 此实例的一个新 String 等效项,但在位置 startIndex 处插入 value。异常 异常类型 条件 ArgumentNullException value 为空引用(Visual Basic 中为 Nothing)。 ArgumentOutOfRangeException startIndex 为负,或大于此实例的长度。 备注 如果 startIndex 等于此实例的长度,则将 value 追加到此实例的末尾。例如,"abc".Insert(2, "XYZ") 的返回值为“abXYZc”。
楼上的.length可以取长度
请用VB实现,谢谢了。不是字节数吧,字符的话.Length
字节的话System.Text.Encoding.Default.GetByteCount(string s)
String 类 | String 成员 | System 命名空间 | Int32 | Concat | CopyTo | Insert | Join | Remove | Replace | Split | Substring | Trim
要求
平台: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family
语言
C#C++JScriptVisual Basic全部显示
在此实例中的指定索引位置插入一个指定的 String 实例。[Visual Basic]
<Serializable>
Public Function Insert( _
ByVal startIndex As Integer, _
ByVal value As String _
) As String
[C#]
[Serializable]
public string Insert(
int startIndex,
string value
);
[C++]
[Serializable]
public: String* Insert(
int startIndex,
String* value
);
[JScript]
public
Serializable
function Insert(
startIndex : int,
value : String
) : String;
参数
startIndex
此插入的索引位置。
value
要插入的 String。
返回值
此实例的一个新 String 等效项,但在位置 startIndex 处插入 value。异常
异常类型 条件
ArgumentNullException value 为空引用(Visual Basic 中为 Nothing)。
ArgumentOutOfRangeException startIndex 为负,或大于此实例的长度。 备注
如果 startIndex 等于此实例的长度,则将 value 追加到此实例的末尾。例如,"abc".Insert(2, "XYZ") 的返回值为“abXYZc”。
if(str.Length==2)
str=str.Insert(1," ");
string finalStr="";
for(int i=0;i<str.Length;i++){
finalStr+=str[i]+"<br>";
}
return finalStr;
}