achive to characters in a string in an other way [modified :D]
-
hi friends, as you know, when you initialize a String, you can achive the characters by:
String str = "hello";
char character = str[0]; //or str[int index]but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks
modified on Sunday, June 29, 2008 1:36 PM
-
hi friends, as you know, when you initialize a String, you can achive the characters by:
String str = "hello";
char character = str[0]; //or str[int index]but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks
modified on Sunday, June 29, 2008 1:36 PM
Sajjad Izadi wrote:
int charPosition = str[0]; //or str[int index]
it returns a char. Your example will show the ascii value of the character at the supplied index and not the character.
Sajjad Izadi wrote:
but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive?
Looks like someone asked you this for an interview ? You can iterate though the string like this
foreach (char c in str)
{
Console.WriteLine(c);
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Sajjad Izadi wrote:
int charPosition = str[0]; //or str[int index]
it returns a char. Your example will show the ascii value of the character at the supplied index and not the character.
Sajjad Izadi wrote:
but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive?
Looks like someone asked you this for an interview ? You can iterate though the string like this
foreach (char c in str)
{
Console.WriteLine(c);
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
oh excuse me :) you are right, it returns a char. but i don't want to use 'foreach', too. i want it for something like an interview :-D. thanks again
modified on Sunday, June 29, 2008 3:15 PM
-
oh excuse me :) you are right, it returns a char. but i don't want to use 'foreach', too. i want it for something like an interview :-D. thanks again
modified on Sunday, June 29, 2008 3:15 PM
I don't think that there is a way without using anything related to string class. I am not sure though.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
hi friends, as you know, when you initialize a String, you can achive the characters by:
String str = "hello";
char character = str[0]; //or str[int index]but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks
modified on Sunday, June 29, 2008 1:36 PM
-
hi friends, as you know, when you initialize a String, you can achive the characters by:
String str = "hello";
char character = str[0]; //or str[int index]but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks
modified on Sunday, June 29, 2008 1:36 PM
If this is the interview question where you have to reverse a string, or ToUpper it or something like that without "using any built in methods" then you can assume you are able to use the char this[int] indexer. Good luck.
Mark Churchill Director Dunn & Churchill Free Download:
Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio. -
How about this
string str = "hello";
char[] c = System.Text.ASCIIEncoding.Unicode.GetChars(
System.Text.ASCIIEncoding.Unicode.GetBytes ((str)));i'll test it, thanks