Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.
Posted
Comments
Karthik_Mahalingam 11-Dec-13 1:19am    
remove the "[]" from return[] words;

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

thanks
 
Share this answer
 
Comments
RaisKazi 11-Dec-13 11:10am    
My 5!
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
 
Share this answer
 
Comments
RaisKazi 11-Dec-13 11:10am    
My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900