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
72
votes
11 answers

How to convert a single char into an int

I have a string of digits, e.g. "123456789", and I need to extract each one of them to use them in a calculation. I can of course access each char by index, but how do I convert it into an int? I've looked into atoi(), but it takes a string as…
jonsb
  • 2,016
  • 3
  • 21
  • 24
70
votes
8 answers

Isn't the size of character in Java 2 bytes?

I used RandomAccessFile to read a byte from a text file. public static void readFile(RandomAccessFile fr) { byte[] cbuff = new byte[1]; fr.read(cbuff,0,1); System.out.println(new String(cbuff)); } Why am I seeing one full character…
Shrinath
  • 7,888
  • 13
  • 48
  • 85
70
votes
9 answers

What is the first character in the sort order used by Windows Explorer?

For example, in a Windows folder, if we create some files and name them 1.html, 2.txt, 3.txt, photo.jpg, zen.png the order will be as is. But if we create another file with the name _file.doc it will be placed at the top. (considering we sort by…
shxfee
  • 5,188
  • 6
  • 31
  • 29
69
votes
4 answers

Insert line break in postgresql when updating text field

I am trying to update a text field in a table of my postgresql database. UPDATE public.table SET long_text = 'First Line' + CHAR(10) + 'Second line.' WHERE id = 19; My intended result is that the cell will look like this: First Line Second…
alexyes
  • 773
  • 2
  • 7
  • 14
69
votes
6 answers

How to reverse String.fromCharCode?

String.fromCharCode(72) gives H. How to get number 72 from char H?
IAdapter
  • 62,595
  • 73
  • 179
  • 242
69
votes
10 answers

SQL query for a carriage return in a string and ultimately removing carriage return

SQL query for a carriage return in a string and ultimately removing carriage return I have some data in a table and there are some carriage returns in places where I don't want them. I am trying to write a query to get all of the strings that…
Maestro1024
  • 3,173
  • 8
  • 35
  • 52
67
votes
12 answers

How do I convert a single char to a string?

I'd like to enumerate a string and instead of it returning chars I'd like to have the iterative variable be of type string. This probably isn't possible to have the iterative type be a string so what is the most efficient way to iterate through this…
Ian R. O'Brien
  • 6,682
  • 9
  • 45
  • 73
67
votes
6 answers

How to check if a String contains any letter from a to z?

Possible Duplicate: C# Regex: Checking for “a-z” and “A-Z” I could just use the code below: String hello = "Hello1"; Char[] convertedString = String.ToCharArray(); int errorCounter = 0; for (int i = 0; i <…
Hendra Anggrian
  • 5,780
  • 13
  • 57
  • 97
66
votes
7 answers

Determine if char is a num or letter

How do I determine if a char in C such as a or 9 is a number or a letter? Is it better to use: int a = Asc(theChar); or this? int a = (int)theChar
Mona
  • 1,043
  • 2
  • 12
  • 21
66
votes
5 answers

What is this char? 65279 ''

I have two strings. one is "\"" and the other is "\"" I think that they are same. However, String.Compare says they are different. This is very strange. Here's my code: string b = "\""; string c = "\""; if (string.Compare(b, c) == 0) { …
장선민
  • 781
  • 1
  • 6
  • 7
65
votes
2 answers

Efficiently repeat a character/string n times in Scala

I would like to do the following more efficiently: def repeatChar(char:Char, n: Int) = List.fill(n)(char).mkString def repeatString(char:String, n: Int) = List.fill(n)(char).mkString repeatChar('a',3) // res0: String = aaa repeatString("abc",3)…
TimY
  • 5,256
  • 5
  • 44
  • 57
65
votes
2 answers

How to get the ASCII value in JavaScript for the characters

Possible Duplicate: Convert character to ASCII code in Javascript my requirement is to get the ASCII value of the alphabet letters... Can anyone suggest how to do this in JavaScript?
Anand Murugan
  • 767
  • 2
  • 7
  • 12
64
votes
14 answers

Should a buffer of bytes be signed or unsigned char buffer?

Should a buffer of bytes be signed char or unsigned char or simply a char buffer? Any differences between C and C++? Thanks.
jackhab
  • 17,128
  • 37
  • 99
  • 136
64
votes
3 answers

Why can't I static_cast between char * and unsigned char *?

Apparently the compiler considers them to be unrelated types and hence reinterpret_cast is required. Why is this the rule?
Nick
  • 2,821
  • 5
  • 30
  • 35
63
votes
7 answers

Is char guaranteed to be exactly 8-bit long?

That's all. Didn't find any similar topic so bear with me it there is.
Ori Popowski
  • 10,432
  • 15
  • 57
  • 79