473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Return the number of the array in c#

3
I got a little problem, i have to return the number of the array of the word that is filled in.
First there is filled in a sentence, and have to be split.
I think i splitted it but now i cant return the number of the index, i only get the number of the char.
I hope that some1 can help me.
Its written in C# console.
Like this: A line of words.
Then type one of the words like : line .
Than i need to get returned 1.
Expand|Select|Wrap|Line Numbers
  1. Console.WriteLine("Please fill in a line of words:");
  2.             string st = Console.ReadLine(); // type the words
  3.             string[] words = st.Split(new char[] { char.Parse(" ") }); // split up the words
  4.  
  5.  
  6. Console.WriteLine("Fill in a word of the line above: ");
  7.                         string LS = Console.ReadLine();
  8.                         //Console.ReadLine();
  9.                         Console.WriteLine(st.IndexOf(LS));
  10.                         Console.ReadLine();  
  11.  
  12.  
  13.  
Hopefully its enough info.
Thanks in andvance

Greetings, Robba.
Nov 9 '07 #1
4 1504
r035198x
13,262 8TB
I got a little problem, i have to return the number of the array of the word that is filled in.
First there is filled in a sentence, and have to be split.
I think i splitted it but now i cant return the number of the index, i only get the number of the char.
I hope that some1 can help me.
Its written in C# console.
Like this: A line of words.
Then type one of the words like : line .
Than i need to get returned 1.
Expand|Select|Wrap|Line Numbers
  1. Console.WriteLine("Please fill in a line of words:");
  2.             string st = Console.ReadLine(); // type the words
  3.             string[] words = st.Split(new char[] { char.Parse(" ") }); // split up the words
  4.  
  5.  
  6. Console.WriteLine("Fill in a word of the line above: ");
  7.                         string LS = Console.ReadLine();
  8.                         //Console.ReadLine();
  9.                         Console.WriteLine(st.IndexOf(LS));
  10.                         Console.ReadLine();  
  11.  
  12.  
  13.  
Hopefully its enough info.
Thanks in andvance

Greetings, Robba.
Why did you declare the array "words" when you never used it?
If you want to search the position of the entered text from that array then you need a loop (or use ArrayList instead of array).
Nov 9 '07 #2
Robba
3
Why did you declare the array "words" when you never used it?
If you want to search the position of the entered text from that array then you need a loop (or use ArrayList instead of array).
Great thanks, fixed it:P
The "words" was used to count the number of words in the progam, i though it wasnot nesesary to show the rest of the program(witch is a lot more lines).
Nov 9 '07 #3
Plater
7,872 Expert 4TB
Not sure what you were looking for?
Expand|Select|Wrap|Line Numbers
  1. for (int i=0; i<words.Length;i++)
  2. {
  3.    //something with this?
  4.    string currentword=words[i];
  5. }
  6.  
Nov 9 '07 #4
Robba
3
Expand|Select|Wrap|Line Numbers
  1.  
  2. Console.WriteLine("Please fill in a line of words:");
  3.             string st = Console.ReadLine(); // type the words
  4.  
  5.             //string[] words = st.Split(new char[] { char.Parse(" ") }); // split up the words
  6.             string[] words = st.Split(' ');
  7.  
  8.  
  9.             if (words.Length == 1)
  10.             {
  11.                 Console.WriteLine("You did not fill in enough words.");
  12.                 Console.ReadLine();
  13.                 return;
  14.             }
  15.             else
  16.             {
  17.                 Console.WriteLine("there are - " + words.Length + " - words in this line");
  18.             }
  19.  
this is the beginning.

Expand|Select|Wrap|Line Numbers
  1.  
  2. // index
  3. Console.WriteLine("This is the words index: ");
  4.                            for (int i = 0; i < words.Length; i++)
  5.  
  6.                             Console.WriteLine("word number - " + i + ": " + words[i]);
  7.  
  8.  
  9.                                                Console.ReadLine();    
  10.                     }
And i was looking for something like this, to get the index of the words in the array.
Nov 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Don | last post by:
I want the server-side php script to return a browser page that is essentially a copy of the original client page that contained the <form> which referenced the php script in the first place....
5
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; ...
2
by: deko | last post by:
Can I return the index number of an array if all I have is the element? For example, if I want to index the alphabet, I can put the letters in the array: Dim varLtr As Variant varLtr =...
8
by: M. Moennigmann | last post by:
Dear all: I would like to write a function that opens a file, reads and stores data into an 2d array, and passes that array back to the caller (=main). The size of the array is not known before...
23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
6
by: alternativa | last post by:
Hi, I have problem with the following function - it was intended to ask a user for a 4-digits number: double ask_for_number (void) { char *notint; char s2; double entered_number;
11
by: Hypnotik | last post by:
Hello everyone. I am writing a program which takes in information to various arrays. I input the info using "set" functions. I then need to output that info from an output function. I'm having...
4
by: CK938 | last post by:
Hi, I'm new to C and I'm trying to read in a file that can have an arbitrary number of lines, and put each line into a string array. I guess my problem is that I dont't want to have to explicitly...
1
by: =?Utf-8?B?RGFya3Jpc2Vy?= | last post by:
Mates, the problem is pretty simple, but I'm unable to manage it... Therefore asking you for help. Situation: Have managed code in C# and unamanged code in C++ DLL. I need to make a call from...
2
by: StevenHu | last post by:
I do not want my iPhone slider to return simple numbers like 1, 2, 3, etc. to the text label, but 15mm, 15.5mm, 16mm, etc., from 15mm to 45mm in increments of .5. So I thought I would put all the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.