您好,欢迎来到华佗养生网。
搜索
您的当前位置:首页Tcl 进阶之路,编程题(1)—— Acronym

Tcl 进阶之路,编程题(1)—— Acronym

来源:华佗养生网

题目:

将一个短语转换为它的首字母缩略词。如下给出了程序的 输入输出 示例。 

InputOutput
As soon as possibleASAP
I'm fine, and you?IFAY
hello-world, hello-tcl.HWHT
_init_design this is also be ok!IDTIABO

参一:

proc abbreviate {phrase} {
    set firstLetters [regexp -all -inline {[[:alpha:]][[:alpha:]']*} $phrase]
    set acronym ""
    foreach letter $firstLetters {
        append acronym [string index $letter 0]
    }
    return [string toupper $acronym]
}

参二:

proc abbreviate {phrase} {
    set tokens [split $phrase " -_"]
    foreach token $tokens {
        lappend res [regexp -nocase -inline {[a-z]} $token]
    }
    return [string toupper [join $res ""]]
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo7.cn 版权所有 湘ICP备2022005869号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务