How can I capitalize the first letter of each word?

前端 未结 20 2366
暖寄归人
暖寄归人 2021-01-14 12:31

I need a script in any language to capitalize the first letter of every word in a file.

Thanks for all the answers.

Stackoverflow rocks!

20条回答
  •  无人共我
    2021-01-14 12:34

    Very basic version for AMOS Basic on the Amiga — only treats spaces as word separators though. I'm sure there is a better way using PEEK and POKE, but my memory is rather rusty with anything beyond 15 years.

    FILE$=Fsel$("*.txt")
    Open In 1,FILE$
    Input #1,STR$
    STR$=Lower$(STR$)
    L=Len($STR)
    LAST$=" "
    NEW$=""
    For I=0 to L-1
      CUR$=MID$(STR$,I,1)
      If LAST$=" "
        NEW$=NEW$+Upper$(CUR$)
      Else
        NEW$=NEW$+$CUR$
      Endif
      LAST$=$CUR$
    Next
    Close 1
    Print NEW$
    

    I miss good old AMOS, a great language to learn with... pretty ugly though, heh.

提交回复
热议问题