将字符串分割只有2件 [英] Splitting a String into only 2 parts

查看:127
本文介绍了将字符串分割只有2件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借此从一个文本框(txtFrom)的字符串并保存第一个字和保存无论是留在另一部分。 (该无论剩下的是一切都会过去的第一个空格)

I want to take a string from a textbox (txtFrom) and save the first word and save whatever is left in another part. (the whatever is left is everything past the first space)

例如字符串=鲍勃·琼斯去商店

Example string = "Bob jones went to the store"

数组[0]将给予鲍勃
阵列[1]将给予琼斯去商店

array[0] would give "Bob"
array[1] would give "jones went to the store"

我知道有 String []数组= txtFrom.Split(''); ,但是给我的6阵列带个人字

I know there is string[] array = txtFrom.Split(' '); , but that gives me an array of 6 with individual words.

推荐答案

使用 String.Split(字符[],Int32)在超载是这样的:

string[] array = txtFrom.Text.Split(new char[]{' '},2);

<一个href="http://msdn.microsoft.com/en-us/library/c1bs0eda.aspx">http://msdn.microsoft.com/en-us/library/c1bs0eda.aspx

这篇关于将字符串分割只有2件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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