char interview questions
Top char frequently asked interview questions
What is the proper way to turn a char[]
into a string?
The ToString()
method from an array of characters doesn't do the trick.
Source: (StackOverflow)
I just want to know if there's a better solution to parse a number from a character in a string (assuming that we know that the character at index n is a number).
String element = "el5";
String s;
s = ""+element.charAt(2);
int x = Integer.parseInt(s);
//result: x = 5
(useless to say that it's just an example)
Source: (StackOverflow)
So I want to iterate for each character in a string.
So I thought:
for (char c : "xyz")
but I get a compiler error:
MyClass.java:20: foreach not applicable to expression type
How can I do this?
Source: (StackOverflow)
Is there a way to turn a char
into a String
or a String
with one letter into a char
(like how you can turn an int
into a double
and a double
into an int
)? (please link to the relevant documentation if you can).
How do I go about finding something like this that I'm only vaguely aware of in the documentation?
Source: (StackOverflow)
I want to convert a std::string into a char* or char[] data type.
std::string str = "string";
char* chr = str;
Results in: “error: cannot convert ‘std::string’ to ‘char’ ...”.
What methods are there available to do this?
Source: (StackOverflow)
How do I parse a String
value in Java to a char
type?
I know how to do it to int and double (for example Integer.parseInt("123")), Is there a class for Strings and Chars?
Source: (StackOverflow)
So I have a char in c#:
char foo = '2';
Now I want to get the 2 into an int. I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2. The following will work:
int bar = Convert.ToInt32(new string(foo, 1));
int.parse only works on strings as well.
Is there no native function in C# to go from a char to int without making it a string? I know this is trivial but it just seems odd that there's nothing native to directly make the conversion.
Source: (StackOverflow)
This question already has an answer here:
For example, I have this
char *buff = "this is a test string";
and want to get "test"
. How can I do that?
Source: (StackOverflow)
I am trying to do some dynamic programming based on the number of characters in a sentence. Which letter of the English alphabet takes up the most pixels on the screen?
Source: (StackOverflow)
In C, I can do like this:
char s[] = "hello";
or
char *s = "hello";
So I wonder what is the difference? I want to know what actually happens in memory allocation during compile time and run time.
Source: (StackOverflow)