开发者

how to assign a char value to string variable in c#

i have a string strText with certain value on it,i need to assign '\0' or charactor a开发者_运维百科t the specified position of strText. ie strText[5]='\0'.how is it possible in c#.


You can use the Insert method to specify the index. You need to give it a string though, so if you can replace '\0' with "\0" or else just call .ToString()

strText = strText.Insert(5, yourChar.ToString());


Strings are immutable, so you will need to convert it to a character array, set the character at the specified position, and then convert back to string:

char[] characters = "ABCDEFG".ToCharArray ();
characters[5] = '\0';
string foo = new String (characters);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜