Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Note: it will be a little bad for me to translate but do not look up

I am writing a program and now I will enter a text in the program and using this keyword to match this text is something related to the lessons but I'm having a problem
I have defined a key word I have assigned a variable name
int a
Console.Write ("Enter Your Sentence");
a = Convert.Toint32 (Console.ReadLine ());
if (keyword == a)
{
Sentence related to mathematics
here the problem is the program word is not the word but it is the whole of the cümlenle my aim is to compare the words with the words of the cümlen one by one how to start here i tried split command but i was not successful

What I have tried:

Console.Write ("Enter Your Sentence");
a = Convert.Toint32 (Console.ReadLine ());
if (keyword == a)
{
Posted
Updated 7-Oct-17 9:35am

1 solution

Go back to the string.Split solution - what you have doesn't work, and won't.
You read a line, but then you try to convert it to an integer - and words don't normally convert to numbers at all. None of the sentences I have typed so far even contain a word that would convert to an integer!
String.Split Method (Char[]) (System)[^]

So start with this:
Console.Write ("Enter Your Sentence: ");
string input = Console.ReadLine ();
string[] words = input.Split(' ');
And see if you can do the next bit yourself.
 
Share this answer
 
v2
Comments
Member 13439463 8-Oct-17 2:54am    
Console.Write("Soruyu Giriniz: ");
string Giriş = Console.ReadLine();
string[] AnahtarKelimeler = Giriş.Split(' ');
if (Giriş == "küme")
{
Console.Write("Ders Matematik");
}
Console.ReadKey();
böyle bir kod yazdım ama sorunum şu bir kelime yazınca çalışıyor tamam ama benim istediğim bir cümle yazınca eğer içinde küme varsa ders matematik demesi
OriginalGriff 8-Oct-17 3:33am    
No, string.Split does not change the input string: it breaks it into separate string which it returns in an array. I stored that array of strings in a variable called "words", you stored it in a variable called "AnahtarKelimeler".
I'd suggest looking at the array, rather than the input string...
Member 13439463 8-Oct-17 7:17am    
teşekkür ederim sayenizde kodu yaptım ama kodu kısaltmak istiyorum biraz
if (textBox1.Text.Contains("küme" || "Kartezyen")) böyle birşey yaptım texbox daki değer küme veya kartezyen ise ders matematik demesini istiyorum bunu formda yapıorum ama hata alıyorum
Error 1 Operator '||' cannot be applied to operands of type 'string' and 'string' c:\users\win7\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 22 40 WindowsFormsApplication2
bunuda yanıtlarsan çok iyi olur şimdiden teşekkürler
OriginalGriff 8-Oct-17 7:21am    
Sorry - this is an English language site, and we only accept questions and comments in that language.
Member 13439463 8-Oct-17 7:41am    
thank you i made the code but i want to shorten the code a bit
if (textBox1.Text.Contains ("set" | "Cartesian")) I did something like this I would like to call the course mathematics if the value of texBox is a set value or cartesian I do it in form but I get an error
Error 1 Operator '||' c: \ users \ win7 \ documents \ visual studio 2010 \ Projects \ WindowsFormsApplication2 \ WindowsFormsApplication2 \ Form1.cs 22 40 WindowsFormsApplication2
it is very good if you answer this in advance thanks in advance

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