将Word成字符数组 [英] Convert a word into character array
本文介绍了将Word成字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何将一个字转换成字符数组?
How do I convert a word into a character array?
可以说我有词火山肺矽病是的,这是一个字!我想借这个字和一个数值分配给它。
Lets say i have the word "Pneumonoultramicroscopicsilicovolcanoconiosis" yes this is a word ! I would like to take this word and assign a numerical value to it.
a = 1
b = 2
... z = 26
int alpha = 1;
int Bravo = 2;
基本代码
basic code
if (testvalue == "a")
{
Debug.WriteLine("TRUE A was found in the string"); // true
FinalNumber = Alpha + FinalNumber;
Debug.WriteLine(FinalNumber);
}
if (testvalue == "b")
{
Debug.WriteLine("TRUE B was found in the string"); // true
FinalNumber = Bravo + FinalNumber;
Debug.WriteLine(FinalNumber);
}
我的问题是如何获得这个词火山肺矽病到一个char绳子,让我可以循环字母逐个?
My question is how do i get the the word "Pneumonoultramicroscopicsilicovolcanoconiosis" into a char string so that I can loop the letters one by one ?
在此先感谢
推荐答案
关于
char[] myArray = myString.ToCharArray();
但你实际上并不需要做这个,如果你想要遍历字符串。你可以简单地做
But you don't actually need to do this if you want to iterate the string. You can simply do
for( int i = 0; i < myString.Length; i++ ){
if( myString[i] ... ){
//do what you want here
}
}
这工作,因为字符串
类实现它自己的索引
。
This works since the string
class implements it's own indexer
.
这篇关于将Word成字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文