Comment detail

LL Golf Hole 2 - 文字列に含まれる単語の最初の文字を大文字にする (Nested Flatten)

標準ライブラリ内でがんばる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
(fun s->String.iter(fun c->try let rec l p=s.[p]<-Char.uppercase s.[p];
l(String.index_from s p c+1)in l 0with _->())" \t\n\r\012\011";s)
"LL day and night";;

(fun s->for i=0to 5do try let rec l p=s.[p]<-Char.uppercase s.[p];
l(String.index_from s p" \t\n\r\012\011".[i]+1)in l 0with _->()done;s)
"LL future";;

#load "str.cma";;
open Str;;
global_substitute(regexp"[A-Za-z0-9][A-Za-z0-9]*") 
(fun s->String.capitalize(matched_string s))
"LL day and night";;

#load "str.cma";;
(fun s->String.concat" "(List.map String.capitalize
(Str.split (Str.regexp"[ \t\n\r\012\011]")s)))
"LL future";;

Index

Feed

Other

Link

Pathtraq

loading...