如何在没有任何分隔符的情况下将字符串拆分为数组或变量? [英] How can I split string into array or variable without any delimiter?

查看:736
本文介绍了如何在没有任何分隔符的情况下将字符串拆分为数组或变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将"12345678"拆分为
第一个变量或arr [0] = 12
第二个变量或arr [1] = 34
第三个变量或arr [2] = 56
第四变量或arr [3] = 78

如何在不使用;,::等任何分隔符的UNIX shell脚本中执行此操作?

I want to split "12345678" into
first variable or arr[0]=12
second variable or arr[1]=34
third variable or arr[2]=56
fourth variable or arr[3]=78

How can I do this in UNIX shell scripting without any delimiter of ;,,: etc...

推荐答案

您可以使用子字符串提取(请参见http://tldp.org/LDP/abs/html/string-manipulation.html [ ^ ]):
You can use the Substring Extraction (see http://tldp.org/LDP/abs/html/string-manipulation.html[^]):
stringInput=12345678
str1=


{stringInput:0:2}#12 str2 =
{stringInput:0:2} # 12 str2=


{stringInput:2:2}#34 str3 =
{stringInput:2:2} # 34 str3=


这篇关于如何在没有任何分隔符的情况下将字符串拆分为数组或变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆