c# help
•
19 Oct 2011, 19:03
•
Journals
okay so the prob is
theres an array
string[]fun it has random stuff reed from a txt
what i need to do is locate the first letters of every element of the fun array
ive got a "for" loop for this obviously
string[1].fun smth like that. i dont know how to define it
theres an array
string[]fun it has random stuff reed from a txt
what i need to do is locate the first letters of every element of the fun array
ive got a "for" loop for this obviously
string[1].fun smth like that. i dont know how to define it
Google will answer that in about 3 seconds.
in c, the index starts with 0
Maybe you mean something like this:
for (int i = 0; i < fun.Length; i++) {
string sentence = fun;
string one = sentence.Substring(0, 1); // gets the first character
string two = sentence.Substring(0, 2); // gets the first and second character
Console.WriteLine( one + " | " + two );
}
Let's say:
string[] fun = new string[2];
fun[0] = "Hello World";
fun[1] = "Number two";
Would output:
H | He
N | Nu
PS: What Mayni said, this is really basic stuff.
ive got a string array full of words starting with the letters "s" and "a"
i need to put these words into a "for" loop which has a "if" inside it which will decide
that the actual words (i) have the "a" or the "s" as the first letter.
if s then im to change the letter colors to red
if a then blue :)
int i;
string szöveg,a="a",b="s",c="i";
string[] stuff1 = System.IO.File.ReadAllLines(@"c:\c#\stuff1.txt");
string[] stuff2 = System.IO.File.ReadAllLines(@"c:\c#\stuff2.txt");
for (i = 0; i <= 100; i++)
szöveg = melee;
{
if (szöveg[0] = a) Console.ForegroundColor = ConsoleColor.Green;
dont mind that the colors not match i was just messing around . stil its not working i cant define how it should find the FIRST letter of the stuff1
it should look like szöveg[0].stuff1 in pascal or smth like that
for(int i = 0; i < s.Length; i++)
{
if(s == ' ')
{
if(s[i+1] == 'a')
{
// do something
}
else if(s[i+1] == 's')
{
// do something else
}
}
}