mathematica处理字符串

时间:2026-02-14 04:38:39

1、首先,给出一个句子a:

a="The eagle flies in the vast sky,the fish swim in the clear water,and all things are in the light of autumn to live a free life.";

mathematica处理字符串

2、对字符串强制换行:

InsertLinebreaks[a,36]

mathematica处理字符串

3、按照空格,把句子分解为单词:

b=StringSplit[a]

4、在单词的左面填充0,使得每个单词的长度为20:

c=StringPadLeft[b,20,"0"];

mathematica处理字符串

5、在右侧填充单词:

d=StringPadRight[b,20,"^o._"];

mathematica处理字符串

6、用“___”把单词两两连接,并换行:

StringRiffle[Partition[b,2] ,"\n","___"]

mathematica处理字符串

© 2026 一点知道
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com