2011-10-10 37 views
0

當我嘗試將字符串映射過來,我得到:如何映射Io中字符串中的字符?

Exception: Sequence does not respond to 'map' 

顯然,IO不落實序列的map方法。那麼如何將字符串序列轉換爲字符列表呢?

+0

可能重複http://stackoverflow.com/questions/4255123/how-do-i -convert-A-字符串到一個列表,在1-10) – mcandre

回答

0

Io目前沒有Sequence asList方法,但可以很容易地添加一個。

Range 

s := "abc" 

# From StackOverflow 
# http://stackoverflow.com/questions/4255123/how-do-i-convert-a-string-to-a-list-in-io/4256258#4256258 
Sequence asList := method(
    result := list() 
    self foreach(x, 
     result append(x) 
    ) 
) 

s asList map(c, 
    "Char: #{c}" interpolate println 
) 

輸出:

Char: a 
Char: b 
Char: c 
的[?我如何將字符串轉換爲在木衛一的列表(