From 181b43cba08795f670770683b951283ea35d53d8 Mon Sep 17 00:00:00 2001 From: pimgeek Date: Tue, 27 May 2014 11:18:39 +0800 Subject: [PATCH 1/2] Update string_to_hump.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加了一项 racket 语言的解决方法 --- string_to_hump.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/string_to_hump.md b/string_to_hump.md index 1a2931c..ed4fa4d 100644 --- a/string_to_hump.md +++ b/string_to_hump.md @@ -29,6 +29,22 @@ ##欢迎补充其它语言的解决方法 +###racket解决方法 (racket 5.2.1) + +```racket +#lang racket +(let* + [(train-str "border-bottom-color") + (splited-str (regexp-split "-" train-str))] + (string-append + (first splited-str) + (apply + string-append + (map + string-titlecase + (rest splited-str))))) +``` + -------------- ###联系我:老齐 qiwsir#gmail.com (# to @) From 8d7b7a48ca0f0876e36641a83e8228363af3bbf8 Mon Sep 17 00:00:00 2001 From: pimgeek Date: Tue, 27 May 2014 12:11:56 +0800 Subject: [PATCH 2/2] Update string_to_hump.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改现有的 racket 解决方法, 让其更加符合可调用的标准. 1 把字符串转换的处理步骤转换为可调用的函数 2 把分隔符参数化, 以便处理以不同情况 3 给出调用方法和正常运行之后看到的输出结果 --- string_to_hump.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/string_to_hump.md b/string_to_hump.md index ed4fa4d..4c30670 100644 --- a/string_to_hump.md +++ b/string_to_hump.md @@ -33,16 +33,22 @@ ```racket #lang racket -(let* - [(train-str "border-bottom-color") - (splited-str (regexp-split "-" train-str))] - (string-append - (first splited-str) - (apply - string-append - (map - string-titlecase - (rest splited-str))))) + +; 定义字符串转换函数 train-to-camel +(define (train-to-camel train-str separator-char) + (let + [(splited-str (regexp-split separator-char train-str))] ; 把原始字符串用 '-' 分成多个单独的单词 + (string-append + (first splited-str) + (apply + string-append + (map + string-titlecase + (rest splited-str)))))) + +; 调用字符串转换函数 train-to-camel +(train-to-camel "this-is-a-var" "-") ; 正常运行的情况下, 应输出 "thisIsAVar" + ``` --------------