分割句子的方法 [英] method to split a sentence

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

问题描述

目前我正在学习.net。我的问题是,如果我必须将一个句子分成一个单词,我怎么能达到这个目的?

i我想尝试





public string [] splitwords()

{



string s = TextBox1 .Text;



string [] words = s.Split('');



返回[ ]单词;

}

但它显示错误返回[] words.plz告诉我如何制作这个。我想要调用它应该给我的功能所有单词。

currently i am studying .net.My question is if i have to split a sentence in to words how i can achieve this?
i am trying like


public string[] splitwords()
{

string s = TextBox1.Text;

string[] words = s.Split(' ');

return[] words;
}
but it is showing error near return[]words.plz tell me how to make this.I want on calling the function it should give me the all the words.

推荐答案

你好,

只返回'words'而不是'[] words',因为它已经在数组形成。



谢谢
Hello ,
Return only 'words' instead of '[]words' as it is already in array formed .

thanks


因为你使用的语法无效而发生错误。

想一想这样:

你的方法 splitwords 被声明为返回一个字符串数组( string [] )。

然后局部变量字也被声明为字符串数组( string [] )。

String.Split 返回一个字符串数组,这样你对变量字的赋值也与它的类型相匹配。

所以既然变量单词并且方法的返回类型属于同一类型,那么您认为应该返回什么?b / b?br / >


我不再说了,言语!





问候,

- Manfred
The error occurs because you are using invalid syntax.
Think about it this way:
Your method splitwords is declared as returning an array of strings (string[]).
Then the local variable words is also declared as being an array of strings (string[]).
String.Split returns an array of strings so your assignment to variable words also matches its type.
So since the variable words and the return type of the method are of the same type, what do you think
you should return?

I shall say no more, words!


Regards,
— Manfred

这篇关于分割句子的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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