0

Hey guys, I want to ask whether in C# I can take a values from a textbox words like in C++ console.readline..

Example :
user : What is Apple
application will take the last word of it which is apple. and will reply
apps: Apple is a fruit

is it possible?

Thanks in advance.. i need to know how to take that last words..

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

Don't really get it.
Do you want to use a textbox as some sort of console?
If you want to extract some strings from a string object, you could use the methods Split or SubString.

1
public String GetLastWord(String input) {
    String[] parts = input.Split(new char[] {' ', '.', '?', '!'}, StringSplitOptions.RemoveEmptyEntries);
    return parts[parts.length-1];
}
0

try this piece of code:

static void Main(string[] args)
        {
            string str1 = "Users: What is Apple?";
            string[] arrayS = str1.Split(' ');
            string str2 = arrayS[arrayS.Length - 1];
            if (str2.Contains("?") || str2.Contains("!") || str2.Contains(".") || str2.Contains(","))
                str2 = str2.Remove(str2.Length - 1, 1);
            Console.WriteLine("{0} is a frut.", str2);
            Console.ReadLine();
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.