Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -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.

View file

@ -2,4 +2,5 @@
category:
- Basic language learning
- String manipulation
- Simple
note: Text processing

View file

@ -0,0 +1,2 @@
'abcdefg' str2ar
{%d nl <<} eachar

View file

@ -0,0 +1 @@
(98 97 98 101 108) ls2lf ar2str nl <<

View file

@ -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);
}

View 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

View file

@ -3,5 +3,5 @@
#symbol Program =>
[
console write:("a" getAt:0 Number).
console write:(CharValue new:97).
console write:(CharValue new &short:97).
].

View file

@ -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!"

View file

@ -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)
}

View file

@ -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"

View file

@ -0,0 +1,6 @@
"encoding is set to utf-8
echo char2nr("a")
"Prints 97
echo nr2char(97)
"Prints a