1.

Solve : C# Help, How do I find the amount of letters in a string??

Answer»

I would like to know how I can know how MANY letters are in the string with out KNOWING the word?

EXAMPLE code:

using System;

public CLASS word
{
public static void Main()
{
string EW = Console.ReadLine();
char o = EW[0];
//I would like to know how many letters are in EW so I can do this.
if (Amount of Letters in EW == 2)
char t =EW[1];
}
}

Can I get some help? if you want to know how long it is, there is a method for that. If you literally need to count the letters A-Z as they appear in the string, then you'll need to loop through the characters in the string, and each one that is A-Z increments the count..Quote from: BC_Programmer on February 27, 2009, 08:16:23 PM

if you want to know how long it is, there is a method for that. If you literally need to count the letters A-Z as they appear in the string, then you'll need to loop through the characters in the string, and each one that is A-Z increments the count..
I'm not interested in the letters A - Z just how long the word is...
How do I use the method you suggest?
BTW thanks for the quick reply!Quote from: hibyy on February 27, 2009, 08:22:58 PM
Quote from: BC_Programmer on February 27, 2009, 08:16:23 PM
if you want to know how long it is, there is a method for that. If you literally need to count the letters A-Z as they appear in the string, then you'll need to loop through the characters in the string, and each one that is A-Z increments the count..
I'm not interested in the letters A - Z just how long the word is...
How do I use the method you suggest?
BTW thanks for the quick reply!

In VB6 it is the "LEN" function- for .NET it is the string method, "length".

For example; if your variable was strval, the length would be "strval.Length()"


Thanks this will help me a lot!

ERROR?
Fixed

public class word
{
public static void Main()
{
string EW = Console.ReadLine();
char o = EW[0];
string L = EW.Length();
if ( EW.Length == 2)
char t =EW[1];
}
}

I got an error!

(7,15): error CS0118: 'string.Length' denotes a 'property' where a 'method' was expected

How do I fix this?


Discussion

No Comment Found