Questions tagged [char]

char refers to the character data-type, representing letters, digits, punctuation marks, control characters, etc. Use this tag for questions relating to and usage of the character data-type.

The keyword char is used in many programming languages, often defining a 1-byte memory location representing ASCII, UTF-8, UTF-16, UTF-32, and ISO-8895-1 character encodings. Arrays of characters can create Strings used to form words, descriptive text, or even extremely large numbers unable to be represented exactly by 32 or 64 bits.

13281 questions
51
votes
5 answers

Return char[]/string from a function

Im fairly new to coding in C and currently im trying to create a function that returns a c string/char array and assigning to a variable. So far, ive observed that returning a char * is the most common solution. So i tried: char* createStr() { …
user1993177
  • 573
  • 2
  • 6
  • 9
50
votes
7 answers

What is the symbol for whitespace in C?

I am trying to figure out how to check if a character is equal to white-space in C. I know that tabs are '\t' and newlines are '\n', but I want to be able to check for just a regular normal space (from the space-bar) inside of an if statement. Does…
Cesar A
  • 663
  • 1
  • 7
  • 10
50
votes
7 answers

How to check the last character of a string in C#?

I want to find the last character of a string in C# and then put it in an if statement. Then if the last character is equal to 'A', 'B' or 'C' a certain action should be performed. How do I get the last character of a string in C#?
esq619
  • 531
  • 1
  • 4
  • 4
50
votes
7 answers

Is there any logic behind ASCII codes' ordering?

I was teaching C to my younger brother studying engineering. I was explaining him how different data-types are actually stored in the memory. I explained him the logistics behind having signed/unsigned numbers and floating point bit in decimal…
this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
49
votes
2 answers

How to concatenate a char onto a string in Rust?

I have tried using the to_string method on the char but this returns a &str when I need a String.
unskilledidiot
  • 689
  • 1
  • 6
  • 11
49
votes
4 answers

Is a string literal in С++ created in static memory?

Is a string literal in C++ created in static memory and destroyed only when the program exits?
yesraaj
  • 46,370
  • 69
  • 194
  • 251
48
votes
5 answers

How do I map a char property using the Entity Framework 4.1 "code only" fluent API?

I have an object that has a char property: public class Product { public char Code { get; set; } } Entity Framework doesn't seem to be able to map chars (this field is missing from the database when I create the database…
dommer
  • 19,610
  • 14
  • 75
  • 137
48
votes
4 answers

char!=(signed char), char!=(unsigned char)

The code below compiles, but has different behavior for the char type than for the int types. In particular cout << getIsTrue< isX::ikIsX >() << endl; cout << getIsTrue< isX::ikIsX >() << endl; cout << getIsTrue<…
user48956
  • 14,850
  • 19
  • 93
  • 154
48
votes
2 answers

How to count the number of times a character appears in a SQL column?

For a user logging table I have in a SQL database, I track the some of the parameters off of a report request. The report allows multiple ID's to be passed to it and I store all of those in a single column in the database column. If this were to…
RSolberg
  • 26,821
  • 23
  • 116
  • 160
47
votes
5 answers

SQL ORDER chars numerically

I have a column of numbers stored as chars. When I do a ORDER BY for this column I get the following: 100 131 200 21 30 31000 etc. How can I order these chars numerically? Do I need to convert something or is there already an SQL command or…
T.T.T.
  • 33,367
  • 47
  • 130
  • 168
47
votes
4 answers

Java - char, int conversions

In Java, the following is allowed: char c = 'A' + 1; Here, c will hold the value 'B'. Above, first the expression is evaluated. So 'A' gets converted to 65, the whole expression evaluates to 66, and then 66 is converted to 'B' since we are storing…
Cosmic_Dust
  • 471
  • 1
  • 4
  • 6
46
votes
5 answers

Java Replace Character At Specific Position Of String?

I am trying to replace a character at a specific position of a string. For example: String str = "hi"; replace string position #2 (i) to another letter "k" How would I do this? Thanks!
01jayss
  • 1,400
  • 6
  • 19
  • 28
45
votes
5 answers

In C, why is sizeof(char) 1, when 'a' is an int?

I tried printf("%d, %d\n", sizeof(char), sizeof('c')); and got 1, 4 as output. If size of a character is one, why does 'c' give me 4? I guess it's because it's an integer. So when I do char ch = 'c'; is there an implicit conversion happening, under…
legends2k
  • 31,634
  • 25
  • 118
  • 222
45
votes
4 answers

casting int to char using C++ style casting

In traditional C you can do: int i = 48; char c = (char)i; //Now c holds the value of 48. //(Of course if i > 255 then c will not hold the same value as i). Which of the c++ casting methods (static_cast, reinterpret_cast) is suited for getting…
Subway
  • 5,286
  • 11
  • 48
  • 59
44
votes
2 answers

How to replace a single character inside a string in Golang?

I am getting a physical location address from a user and trying to arrange it to create a URL that would use later to get a JSON response from Google Geocode API. The final URL string result should be similar to this one, without spaces:…
moalf
  • 443
  • 1
  • 5
  • 7