Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,5 @@
|
|||
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses). For example, the character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
|
||||
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
|
||||
|
||||
For example, the character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
|
||||
|
||||
Conversely, given a code, print out the corresponding character.
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@
|
|||
category:
|
||||
- Basic language learning
|
||||
- String manipulation
|
||||
- Simple
|
||||
note: Text processing
|
||||
|
|
|
|||
2
Task/Character-codes/Babel/character-codes-1.pb
Normal file
2
Task/Character-codes/Babel/character-codes-1.pb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
'abcdefg' str2ar
|
||||
{%d nl <<} eachar
|
||||
1
Task/Character-codes/Babel/character-codes-2.pb
Normal file
1
Task/Character-codes/Babel/character-codes-2.pb
Normal file
|
|
@ -0,0 +1 @@
|
|||
(98 97 98 101 108) ls2lf ar2str nl <<
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
import std.stdio, std.utf;
|
||||
|
||||
void main() {
|
||||
import std.stdio, std.utf;
|
||||
|
||||
string test = "a";
|
||||
size_t index = 0;
|
||||
|
||||
// Get four-byte utf32 value for index 0
|
||||
// this returns dchar, so cast it to numeric.
|
||||
writeln(cast(uint)test.decode(index));
|
||||
// Get four-byte utf32 value for index 0.
|
||||
writefln("%d", test.decode(index));
|
||||
|
||||
// 'index' has moved to next character position in input.
|
||||
// 'index' has moved to next character input position.
|
||||
assert(index == 1);
|
||||
}
|
||||
|
|
|
|||
28
Task/Character-codes/Eiffel/character-codes.e
Normal file
28
Task/Character-codes/Eiffel/character-codes.e
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class
|
||||
APPLICATION
|
||||
inherit
|
||||
ARGUMENTS
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Run application.
|
||||
local
|
||||
c8: CHARACTER_8
|
||||
c32: CHARACTER_32
|
||||
do
|
||||
c8 := '%/97/' -- using code value notation
|
||||
c8 := '%/0x61/' -- same as above, but using hexadecimal literal
|
||||
print(c8.natural_32_code) -- prints "97"
|
||||
print(c8) -- prints the character "a"
|
||||
|
||||
c32 := 'a' -- using character literal
|
||||
print(c32.natural_32_code) -- prints "97"
|
||||
print(c32) -- prints "U+00000061"
|
||||
|
||||
--c8 := 'π' -- compile-time error (c8 does not have enough range)
|
||||
c32 := 'π' -- assigns Unicode value 960
|
||||
end
|
||||
end
|
||||
|
|
@ -3,5 +3,5 @@
|
|||
#symbol Program =>
|
||||
[
|
||||
console write:("a" getAt:0 Number).
|
||||
console write:(CharValue new:97).
|
||||
console write:(CharValue new &short:97).
|
||||
].
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
println[char["a"]] // prints 97
|
||||
println[chars["a"]] // prints [97] (an array)
|
||||
println[char[97]] // prints a
|
||||
println[char["Frink rules!"]] // prints [70, 114, 105, 110, 107, 32, 114, 117, 108, 101, 115, 33]
|
||||
println[[70, 114, 105, 110, 107, 32, 114, 117, 108, 101, 115, 33]] // prints "Frink rules!"
|
||||
|
|
|
|||
|
|
@ -3,14 +3,19 @@ package main
|
|||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// yes, there is more concise syntax, but this makes
|
||||
// the data types very clear.
|
||||
var b byte = 'a'
|
||||
var r rune = 'π'
|
||||
var s string = "aπ"
|
||||
// yes, there is more concise syntax, but this makes
|
||||
// the data types very clear.
|
||||
var b byte = 'a'
|
||||
var r rune = 'π'
|
||||
var s string = "aπ"
|
||||
|
||||
fmt.Println(b, r, s)
|
||||
for _, c := range s { // this gives c the type rune
|
||||
fmt.Println(c)
|
||||
}
|
||||
fmt.Println(b, r, s)
|
||||
fmt.Println("string cast to []rune:", []rune(s))
|
||||
// A range loop over a string gives runes, not bytes
|
||||
fmt.Print(" string range loop: ")
|
||||
for _, c := range s {
|
||||
fmt.Print(c, " ") // c is type rune
|
||||
}
|
||||
// We can also print the bytes of a string without an explicit loop
|
||||
fmt.Printf("\n string bytes: % #x\n", s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
document.write('a'.charCodeAt(0)); // prints "97"
|
||||
document.write(String.fromCharCode(97)); // prints "a"
|
||||
console.log('a'.charCodeAt(0)); // prints "97"
|
||||
console.log(String.fromCharCode(97)); // prints "a"
|
||||
|
|
|
|||
6
Task/Character-codes/Vim-Script/character-codes.vim
Normal file
6
Task/Character-codes/Vim-Script/character-codes.vim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
"encoding is set to utf-8
|
||||
echo char2nr("a")
|
||||
"Prints 97
|
||||
|
||||
echo nr2char(97)
|
||||
"Prints a
|
||||
Loading…
Add table
Add a link
Reference in a new issue