如何查找和替换任何单个文本字符的第一次出现 (Excel)

How to find and replace the first occurrence of any single text character (Excel)

我需要替换或替换 excel 行中单个文本字符的第一个实例。

current: B01 TEST TEST TEST A W B 0 A
expected result where first "A" that is on its own is replaced with "|": B01 TEST TEST TEST | W B 0 A

问题是,每一行都有一个单独分段的字符,但它们都是不同的(有些是 A,有些是 W,有些是 R,等等)。我可以使用哪个函数来查找被空格包围的单个文本字符的第一个实例?

在 Office 365 中,您可以使用 =AGGREGATE(15,6,FIND(" "&CHAR(SEQUENCE(26,,65))&" ",A19),1)

旧版本:=AGGREGATE(15,6,FIND(" "&{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}&" ",A19),1)

编辑:Mayukh 建议的更好版本

=AGGREGATE (15,6,FIND(" "&CHAR(ROW(:))&" ",A19),1)

这使用 Office 365 LET 和 SEQUENCE 并且不依赖于它是大写字符。它将用 |:

替换两边有 space 的第一个字符,无论是字母、数字还是特殊字符
=LET(rng,A1,
    sq,SEQUENCE(LEN(rng)-3),
    md,MID(rng,sq,3),
    lft,LEFT(md),
    rt,RIGHT(md),
    REPLACE(rng,MIN(IF((lft=" ")*(rt=" "),sq+1)),1,"|"))