String must be exactly one character long

前端 未结 4 669
耶瑟儿~
耶瑟儿~ 2021-01-29 10:07

I have what I think is an easy problem. For some reason the following code generates the exception, \"String must be exactly one character long\".

int n = 0;
for         


        
4条回答
  •  萌比男神i
    2021-01-29 11:03

    Your hexOutput is a string, and I'm assuming charMsg is a character array. Suppose the first element in charMsg is 'p', or hex value 70. The documentation for Convert.ToChar(string) says it'll use just the first character of the string ('7'), but it's wrong. It'll throw this error. You can test this with a static example, like charMsg[n] = Convert.ToChar("70");. You'll get the same error.

    Are you trying to replace characters with hex values? If so, you might try using a StringBuilder object instead of your array assignments.

提交回复
热议问题