Replacing one character with another in a string

谁都会走 提交于 2020-01-01 23:58:24

问题


I have a data like below:

A:B:C:D

and I want to replace the C with data (say, Z) so that it may look like

A:B:Z:D

How can I do it?


回答1:


=SUBSTITUTE(A1,"C","Z")

Although I wasn't clear on whether you wanted G or Z, you mentioned G but your example output shows Z.




回答2:


If you have A:B:C:D in cell A1, then this works:

=CONCATENATE(MID(A1, 1, SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + SEARCH(":", A1)), "Z", MID(MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) - SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1), SEARCH(":", MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) - SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1)), LEN(MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) - SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1))))

I know it's incredibly convoluted but it works.

EDIT: And to be clear, you'd replace "Z" with the data you want to add in.



来源:https://stackoverflow.com/questions/11517628/replacing-one-character-with-another-in-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!