Questions tagged [character]

Refers to a symbol that represents a letter or number. Also, the bit pattern used to represent such a symbol.

In computer and machine-based telecommunications terminology, a character is a unit of information that roughly corresponds to a grapheme, grapheme-like unit, or symbol, such as in an alphabet or syllabary in the written form of a natural language. Examples of characters include letters, numerical digits, and common punctuation marks (such as '.' or '-'). The concept also includes control characters, which do not correspond to symbols in a particular natural language, but rather to other bits of information used to process text in one or more languages. Computers and communication equipment represent characters using a character encoding that assigns each character to something — an integer quantity represented by a sequence of bits, typically — that can be stored or transmitted through a network. Two examples of popular encodings are ASCII and the UTF-8 encoding for Unicode.

7762 questions
281
votes
16 answers

How can I check if a single character appears in a string?

In Java is there a way to check the condition: "Does this single character appear at all in string x" without using a loop?
barfoon
  • 27,481
  • 26
  • 92
  • 138
252
votes
2 answers

Remove first 4 characters of a string with PHP

How can I remove the first 4 characters of a string using PHP?
Belgin Fish
  • 19,187
  • 41
  • 102
  • 131
227
votes
14 answers

What method in the String class returns only the first N characters?

I'd like to write an extension method to the String class so that if the input string to is longer than the provided length N, only the first N characters are to be displayed. Here's how it looks like: public static string TruncateLongString(this…
Richard77
  • 20,343
  • 46
  • 150
  • 252
189
votes
8 answers

Convert data.frame column format from character to factor

I would like to change the format (class) of some columns of my data.frame object (mydf) from charactor to factor. I don't want to do this when I'm reading the text file by read.table() function. Any help would be appreciated.
Rasoul
  • 3,758
  • 5
  • 26
  • 34
187
votes
7 answers

How to get the number of characters in a string

How can I get the number of characters of a string in Go? For example, if I have a string "hello" the method should return 5. I saw that len(str) returns the number of bytes and not the number of characters so len("£") returns 2 instead of 1 because…
Ammar
  • 5,070
  • 8
  • 28
  • 27
171
votes
17 answers

How to check if character is a letter in Javascript?

I am extracting a character in a Javascript string with: var first = str.charAt(0); and I would like to check whether it is a letter. Strangely, it does not seem like such functionality exists in Javascript. At least I cannot find it. How can I…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
166
votes
3 answers

Remove all special characters from a string in R?

How to remove all special characters from string in R and replace them with spaces ? Some special characters to remove are : ~!@#$%^&*(){}_+:"<>?,./;'[]-= I've tried regex with [:punct:] pattern but it removes only punctuation marks. Question 2 :…
Qbik
  • 5,885
  • 14
  • 62
  • 93
160
votes
2 answers

Why is the alphabet split into multiple ranges in this C code?

In a custom library I saw an implementation: inline int is_upper_alpha(char chValue) { if (((chValue >= 'A') && (chValue <= 'I')) || ((chValue >= 'J') && (chValue <= 'R')) || ((chValue >= 'S') && (chValue <= 'Z'))) return…
Vladimir Ch.
  • 1,004
  • 1
  • 8
  • 16
158
votes
10 answers

How to index characters in a Golang string?

How to get an "E" output rather than 69? package main import "fmt" func main() { fmt.Print("HELLO"[1]) } Does Golang have function to convert a char to byte and vice versa?
user977828
  • 7,259
  • 16
  • 66
  • 117
150
votes
1 answer

How can I use modulo operator (%) in JavaScript?

How can I use modulo operator (%) in calculation of numbers for JavaScript projects?
Ziyaddin Sadigov
  • 8,893
  • 13
  • 34
  • 41
145
votes
20 answers

Max length UITextField

When I've tried How to you set the maximum number of characters that can be entered into a UITextField using swift?, I saw that if I use all 10 characters, I can't erase the character too. The only thing I can do is to cancel the operation (delete…
giorgionocera
  • 6,428
  • 6
  • 20
  • 17
140
votes
5 answers

Count occurrences of a char in plain text file

Is there any way under linux/terminal to count, how many times the char f occurs in a plain text file?
cupakob
  • 8,411
  • 24
  • 67
  • 76
135
votes
14 answers

Converting String to "Character" array in Java

I want to convert a String to an array of objects of Character class but I am unable to perform the conversion. I know that I can convert a String to an array of primitive datatype type "char" with the toCharArray() method but it doesn't help in…
kgd
  • 1,666
  • 2
  • 11
  • 15
134
votes
18 answers

Find out if Character in String is emoji?

I need to find out whether a character in a string is an emoji. For example, I have this character: let string = "" let character = Array(string)[0] I need to find out if that character is an emoji.
Andrew
  • 7,693
  • 11
  • 43
  • 81
129
votes
13 answers

Creating Unicode character from its number

I want to display a Unicode character in Java. If I do this, it works just fine: String symbol = "\u2202"; symbol is equal to "∂". That's what I want. The problem is that I know the Unicode number and need to create the Unicode symbol from that. …
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202