Computer Science/프로그래밍언어

OCaml Tutorial | String 다루기

토마토. 2022. 3. 18. 16:13

- 내가 원하는 것

- 파이썬처럼 f"{variable_name}" + "HI" + " " 하기

 

OCAML Tutorial 18/33: The String Module in OCAML - YouTube

# String.length "String";;
- : int = 6

# let s = "we are checking the String module";;
val s : string = "we are checking the String module"

# String.length s;;
- : int = 33

# String.sub s 3 3 ;;
- : string = "are"
# String.sub s 3 12;;
- : string = "are checking"

# "this"^" "^"is";;
- : string = "this is"

# let l = ["this";"is";"a"];;
val l : string list = ["this"; "is"; "a"]
# String.concat " " l;;
- : string = "this is a"
# let s = String.concat " " l;;
val s : string = "this is a"

# String.iter (fun x -> print_char x) s;;
this is a- : unit = ()

# String.map (fun x -> Char.uppercase_ascii x) s;;
- : string = "THIS IS A"

# open String;;
# open Char;;
# uppercase_ascii 'c';;
- : char = 'C'

# let s2upper = String.uppercase_ascii;;
val s2upper : string -> string = <fun>
# s2upper "test";;
- : string = "TEST"