EzDevInfo.com

char interview questions

Top char frequently asked interview questions

.NET / C# - Convert char[] to string

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)

Java: parse int value from a char

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)

Advertisements

How do I apply the for-each loop to every character in a String?

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)

In Java how does one turn a String into a char or a char into a String?

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)

How to convert a std::string to const char* or char*?

How can I convert an std::string to a char* or a const char*?


Source: (StackOverflow)

std::string to char*

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 to convert/parse from String to char in java?

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)

C# char to int

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)

In Java, is the result of the addition of two chars an int or a char?

When adding 'a' + 'b' it produces 195. Is the output datatype char or int?


Source: (StackOverflow)

How to convert char to integer in C? [duplicate]

Possible Duplicates:
How to convert a single char into an int
Character to integer in C

Can any body tell me how to convert a char to int?

char c[]={'1',':','3'};

int i=int(c[0]);

printf("%d",i);

When I try this it gives 49.


Source: (StackOverflow)

Get a substring of a char* [duplicate]

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)

Which letter of the English alphabet takes up most pixels?

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)

How to convert a char to a string in Java?

I have a char and I need a String. How do I convert from one to the other?


Source: (StackOverflow)

What is an unsigned char?

In C/C++, what is an unsigned char used for? How is this different from a regular char?


Source: (StackOverflow)

What is the difference between char s[] and char *s in C?

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)