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
125
votes
16 answers

Indexes of all occurrences of character in a string

The following code will print 2 String word = "bannanas"; String guess = "n"; int index; System.out.println( index = word.indexOf(guess) ); I would like to know how to get all the indexes of "n" ("guess") in the string "bannanas" The expected…
Trufa
  • 39,971
  • 43
  • 126
  • 190
124
votes
23 answers

Set the maximum character length of a UITextField in Swift

I know there are other topics on this, but I can't seem to find out how to implement it. I'm trying to limit a UITextField to only five characters. Preferably alphanumeric, -, ., and _. I've seen this code: func textField(textField: UITextField,…
ishkur88
  • 1,265
  • 2
  • 9
  • 12
119
votes
2 answers

Display special characters when using print statement

I would like to display the escape characters when using print statement. E.g. a = "Hello\tWorld\nHello World" print a Hello World Hello World I would like it to display: "Hello\tWorld\nHello\sWorld"
Ian Phillips
  • 1,191
  • 2
  • 8
  • 3
117
votes
5 answers

Get the first character of the first string in a list?

How would I get the first character from the first string in a list in Python? It seems that I could use mylist[0][1:] but that does not give me the first character. >>> mylist = [] >>> mylist.append("asdf") >>> mylist.append("jkl;") >>>…
Trcx
  • 4,164
  • 6
  • 30
  • 30
115
votes
5 answers

Can I use an at symbol (@) inside URLs?

Is it safe to use an @ symbol as part of a user? For example, a possible URL would be http://example.com/@dave. The idea is that, nowadays, users are commonly called "@user", so why not make the user page "@username"?
Geoff
  • 9,470
  • 13
  • 52
  • 67
110
votes
15 answers

How to remove certain characters from a string in C++?

For example I have a user input a phone number. cout << "Enter phone number: "; INPUT: (555) 555-5555 cin >> phone; I want to remove the "(", ")", and "-" characters from the string. I've looked at the string remove, find and replace functions…
SD.
  • 3,089
  • 10
  • 26
  • 21
102
votes
2 answers

How to get the last X Characters of a Golang String?

If I have the string "12121211122" and I want to get the last 3 characters (e.g. "122"), is that possible in Go? I've looked in the string package and didn't see anything like getLastXcharacters.
sourcey
  • 2,481
  • 5
  • 16
  • 13
102
votes
5 answers

How can I check the first character in a string in Bash or Unix shell?

I'm writing a script in Unix where I have to check whether the first character in a string is "/" and if it is, branch. For example, I have a string: /some/directory/file I want this to return 1, and: server@10.200.200.20:/some/directory/file to…
canecse
  • 1,772
  • 3
  • 16
  • 20
101
votes
3 answers

How many characters can be stored in 4KB?

How many characters can i store in 4kb when the characters are in utf-8 encoding ?
Pockata
  • 1,518
  • 3
  • 13
  • 13
100
votes
16 answers

range over character in python

Is there an way to range over characters? something like this. for c in xrange( 'a', 'z' ): print c I hope you guys can help.
huan
  • 1,121
  • 2
  • 8
  • 6
98
votes
7 answers

Characters allowed in GET parameter

Which characters are allowed in GET parameters without encoding or escaping them? I mean something like this: http://www.example.org/page.php?name=XYZ What can you have there instead of XYZ? I think only the following characters: a-z…
caw
  • 30,999
  • 61
  • 181
  • 291
96
votes
4 answers

What is the maximum number of bytes for a UTF-8 encoded character?

What is the maximum number of bytes for a single UTF-8 encoded character? I'll be encrypting the bytes of a String encoded in UTF-8 and therefore need to be able to work out the maximum number of bytes for a UTF-8 encoded String. Could someone…
Edd
  • 8,402
  • 14
  • 47
  • 73
96
votes
15 answers

How can I read a single character at a time from a file in Python?

In Python, given the name of a file, how can I write a loop that reads one character each time through the loop?
kaushik
  • 5,609
  • 4
  • 23
  • 17
95
votes
6 answers

"\n" or '\n' or std::endl to std::cout?

It was many years now since I stopped using std::endl to end lines when writing to std::cout, and started using "\n" instead. But now I start seeing more snippets of code using '\n' instead, and I started wonder what might be best. Besides the…
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
94
votes
14 answers

How to avoid pressing Enter with getchar() for reading a single character only?

In the next code: #include int main(void) { int c; while ((c=getchar())!= EOF) putchar(c); return 0; } I have to press Enter to print all the letters I entered with getchar, but I don't want to do this, what I want…
javier
  • 1,705
  • 2
  • 18
  • 24