472,793 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,793 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 1479
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.