Questions tagged [char]

char typically refers to a character data-type, representing letters of text.

char typically refers to a character data-type, representing letters of text as well as digits, punctuation marks, control characters, etc.

11976 questions
3585
votes
18 answers

Why is char[] preferred over String for passwords?

In Swing, the password field has a getPassword() (returns char[]) method instead of the usual getText() (returns String) method. Similarly, I have come across a suggestion not to use String to handle passwords. Why does String pose a threat to…
Ahamed
  • 36,657
  • 12
  • 35
  • 67
955
votes
8 answers

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*?
user37875
  • 12,522
  • 9
  • 34
  • 43
869
votes
12 answers

How to convert a char to a String?

I have a char and I need a String. How do I convert from one to the other?
Landon Kuhn
  • 61,957
  • 42
  • 100
  • 130
536
votes
14 answers

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

In C, one can use a string literal in a declaration like this: char s[] = "hello"; or like this: char *s = "hello"; So what is the difference? I want to know what actually happens in terms of storage duration, both at compile and run time.
user188276
498
votes
17 answers

What is an unsigned char?

In C/C++, what an unsigned char is used for? How is it different from a regular char?
Landon Kuhn
  • 61,957
  • 42
  • 100
  • 130
438
votes
7 answers

.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.
BuddyJoe
  • 64,613
  • 107
  • 281
  • 451
421
votes
15 answers

How to convert a char array back to a string?

I have a char array: char[] a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'}; My current solution is to do String b = new String(a); But surely there is a better way of doing this?
chutsu
  • 12,484
  • 18
  • 60
  • 83
388
votes
18 answers

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?
user1598585
364
votes
4 answers

How can I convert a character to a integer in Python, and viceversa?

I want to get, given a character, its ASCII value. For example, for the character a, I want to get 97, and vice versa.
Manuel Araoz
  • 14,795
  • 21
  • 67
  • 91
297
votes
11 answers

Delete last char of string

I am retrieving a lot of information in a list, linked to a database and I want to create a string of groups, for someone who is connected to the website. I use this to test but this is not dynamic, so it is really bad: string strgroupids = "6"; I…
Kiwimoisi
  • 3,664
  • 6
  • 25
  • 60
283
votes
20 answers

Why is there no Char.Empty like String.Empty?

Is there a reason for this? I am asking because if you needed to use lots of empty chars then you get into the same situation as you would when you use lots of empty strings. Edit: The reason for this usage was this: myString.Replace ('c', '') So…
Joan Venge
  • 269,545
  • 201
  • 440
  • 653
279
votes
4 answers

How to convert a char array to a string?

Converting a C++ string to a char array is pretty straightorward using the c_str function of string and then doing strcpy. However, how to do the opposite? I have a char array like: char arr[ ] = "This is a test"; to be converted back to: string str…
RajSanpui
  • 10,358
  • 29
  • 69
  • 134
233
votes
13 answers

Single quotes vs. double quotes in C or C++

When should I use single quotes and double quotes in C or C++ programming?
Vishwanath Dalvi
  • 31,604
  • 36
  • 115
  • 146
232
votes
7 answers

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 =…
Noya
  • 3,649
  • 3
  • 22
  • 31
217
votes
14 answers

How to convert/parse from String to char in java?

How do I parse a String value to a char type, in Java? I know how to do it to int and double (for example Integer.parseInt("123")). Is there a class for Strings and Chars?
Yokhen
  • 4,180
  • 8
  • 27
  • 50
1
2 3
99 100