2013年2月13日水曜日

開発環境

『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-87311-425-5) の4章(JavaScriptのオブジェクト)練習問第4-5.を解いてみる。

その他参考書籍

4-5.

コード(BBEdit)

var str = "apple.orange-strawberry,lemon-.lime",
    a = str.replace(/[,.]/g, ",").split(","),
    result = str + "\n",
    i, max;
for (i = 0, max = a.length; i < max; i += 1) {
    result += i + ": " + a[i] + "\n";
}
$('#pre0').text(result);



ちなみにPython3kの場合。

コード(BBEdit)

sample.py

#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-

import re
s = "apple.orange-strawberry,lemon-.lime"
for ch in re.sub(r"[,.]", ",", s).split(","):
    print(ch)

入出力結果(Terminal)

$ ./sample.py
apple
orange-strawberry
lemon-
lime
$

0 コメント:

コメントを投稿