首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

判断listbox里面的值的有关问题

2012-04-10 
判断listbox里面的值的问题listbox下面有下面几个项目beginifthenwhiledoend我想通过判断里面的字符如

判断listbox里面的值的问题
listbox下面有下面几个项目
begin  
if  
then  
while  
do  
end
<
>=
我想通过判断里面的字符
如果items里的值是
begin 
就在后面加上 ( begin 1 )
如果是
if
就在后面加上 (if 2)
如果是
<
后面加上 ( < 3 )
最后结果
begin ( begin 1 )
if (if 2)
then 
while  
do  
end
< ( < 3 )
>=
最好能对齐
各位有没有好的实现方法 在这里谢过了

[解决办法]
try this

C# code
for (int i = 0; i < listBox1.Items.Count; i++)            {                if (listBox1.Items[i].ToString().Equals("begin"))                {                    listBox1.Items.RemoveAt(i);                    listBox1.Items.Insert(i, @"begin"+"\t"+"(begin 1)");                }                else if (listBox1.Items[i].ToString().Equals("if"))                {                    listBox1.Items.RemoveAt(i);                    listBox1.Items.Insert(i, @"if"+"\t"+"(if 2)");                }                else if (listBox1.Items[i].ToString().Equals("<"))                {                    listBox1.Items.RemoveAt(i);                    listBox1.Items.Insert(i, @"<\t"+"\t"+"(< 3)");                }            }
[解决办法]
探讨

如何用switch语句进行判定??
引用:

try this
C# code

for (int i = 0; i < listBox1.Items.Count; i++)
{
if (listBox1.Items[i].ToString().Equals("begin"))
……

[解决办法]
探讨

好的 写出来了 谢谢
对了 请教个语法,就是如何判定 itms里面的内的内容为数字??
其实就是想问 如何取出 item里的字符串然后判定是数字??
引用:

引用:

如何用switch语句进行判定??
引用:

try this
C# code

for (int i = 0; i < listBox1.It……

热点排行