如何拆分字符串?
假设我有一个字符串狗、猫、老鼠、鸟"
Lets say i have a string "dog, cat, mouse,bird"
我的实际目标是将这些动物中的每一个都插入到一个列表框中,这样它们就会成为列表框中的项目.
My actual goal is to insert each of those animals into a listBox, so they would become items in a list box.
但如果我知道如何拆分字符串,我想我知道如何插入这些项目.或者有人知道更好的方法吗?
but i think i get the idea on how to insert those items if i know how to split the string. or does anyone know a better way to do this?
我使用asp c#
string[] tokens = text.Split(',');
for (int i = 0; i < tokens.Length; i++)
{
yourListBox.Add(new ListItem(token[i], token[i]));
}
这篇关于如何将字符串拆分为多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!