如何将字符串拆分为多个值? [英] How do i split a String into multiple values?

查看:18
本文介绍了如何将字符串拆分为多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何拆分字符串?

假设我有一个字符串狗、猫、老鼠、鸟"

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]));
    }

这篇关于如何将字符串拆分为多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆