如何将字符串拆分为单词 [英] How to split a string into word
本文介绍了如何将字符串拆分为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在研究字符串的拆分.我想将字符串拆分为单词,然后将所有这些单词显示在文本框中.我该怎么办?
neaS
Hi all,
I am working on spliting of string. I want to split a string into words and show all those word into a textbox. How could I do that?
neaS
推荐答案
using System;
class Program
{
static void Main()
{
string s = "there is a cat";
//
// Split string on spaces.
// ... This will separate all the words.
//
string[] words = s.Split(' ');
foreach (string word in words)
{
Console.WriteLine(word);
}
}
}
输出
Output
there
is
a
cat
使用 String.Split [ ^ ]
Imports System.Text.RegularExpressions
Private Function SplitWords(ByVal s As String) As String()
Return Regex.Split(s, "\s+")
End Function
Dim parts as String()="abc,pqr"
words = parts.Split(",")
它将以逗号,"为基础将字符串分割成单词...
it will split string in words on the comma '','' basis...
这篇关于如何将字符串拆分为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文