Replacing one character with another in a string

2019-04-18 03:25发布

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?

2条回答
地球回转人心会变
2楼-- · 2019-04-18 03:55

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.

查看更多
爷的心禁止访问
3楼-- · 2019-04-18 04:03

=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.

查看更多
登录 后发表回答