在指数X更改字符的字符串 [英] Change string char at index X

查看:95
本文介绍了在指数X更改字符的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很久如何做一个简单的字符串操作在 UNIX

I'm searched for a long time how to do a simple string manipulation in UNIX

我有这个字符串:

theStr='...............'

和我需要到5字符更改为A,怎样才能做到?

And I need to change the 5th char to A, How can it be done?

C#是这样的做 theStr [4] ='A'; //从零开始的索引。

推荐答案

您可以用 SED 实现这一点,流线编辑:

You can achieve this with sed, the stream line editor:

回声$ theStr | SED小号/./ A / 5

首先,你管$ theStr的输出sed的,其中具有取代第五个字符。

First you pipe the output of $theStr to sed, which replaces the fifth character with A.

这篇关于在指数X更改字符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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