Sharepoint:计算列替换所有空格

时间:2022-12-03 00:14:44

Seems like it would be a simple thing really (and it may be), but I'm trying to take the string data of a column and then through a calculated column, replace all the spaces with %20's so that the HTML link in the workflow produced email will actually not break off at the first space.

看起来它确实是一件简单的事情(也可能是这样),但我正在尝试获取列的字符串数据,然后通过计算列,用%20替换所有空格,以便在工作流产生的电子邮件实际上不会在第一个空间中断。

For example, we have this in our source column:

例如,我们在源列中有这个:

file:///Z:/data/This is our report.rpt

file:/// Z:/ data /这是我们的report.rpt

And would like to end up with this in the calculated column:

并希望在计算列中最终得到这个:

file:///Z:/data/This%20is%20our%20report.rpt

Already used the REPLACE, and made up a ghastly super nested REPLACE/SEARCH version, but the problem there is that you have to nest for EACH potential space, and if you don't know how many up front, it doesn't work, or will miss some.

已经使用了REPLACE,并构成了一个可怕的超级嵌套REPLACE / SEARCH版本,但问题是你必须为每个潜在空间嵌套,如果你不知道预先有多少,它就不起作用,或者会遗漏一些。

Have any of you come across this scenario and how did you handle it?

你有没有遇到这种情况,你是如何处理它的?

Thanks in advance!

提前致谢!

3 个解决方案

#1


As far as I know there is no generic solution using the calculated-column syntax. The standard solution for this situation is using an ItemAdded (/ItemUpdated) event and initializing the field value from code.

据我所知,没有使用计算列语法的通用解决方案。这种情况的标准解决方案是使用ItemAdded(/ ItemUpdated)事件并从代码初始化字段值。

#2


I was able to solve this issue for my circumstances by using a series of calculated columns.

通过使用一系列计算列,我能够针对我的情况解决这个问题。

In the first calculated column (C1) I entered a formula to remove the first space, something like this**: =IF(ISNUMBER(FIND(" ",[Title])),REPLACE([Title],FIND(" ",[Title]),1,"%20"),[Title])

在第一个计算列(C1)中,我输入了一个公式来删除第一个空格,如下所示**:= IF(ISNUMBER(FIND(“”,[Title])),REPLACE([Title],FIND(“” ,[标题]),1, “%20”),[标题])

In the second Calculated column (C2) I used: =IF(ISNUMBER(FIND(" ",[C1])),REPLACE([C1],FIND(" ",[C1]),1,"%20"),[C1]).

在我使用的第二个计算列(C2)中:= IF(ISNUMBER(FIND(“”,[C1])),REPLACE([C1],FIND(“”,[C1]),1,“%20”) ,[C1])。

In my case, I wanted to encode up to four spaces, so I used 3 calculated columns (C1, C2, C3) in the same fashion and got the desired result.

在我的情况下,我想编码最多四个空格,所以我以相同的方式使用3个计算列(C1,C2,C3)并获得所需的结果。

This is not as efficient as using a single calculated column, but if SUBSTITUTE will not work in your SharePoint environment, and you cannot use an event handler or workflow, it may offer a workable alternative.

这不如使用单个计算列有效,但如果SUBSTITUTE在SharePoint环境中不起作用,并且您无法使用事件处理程序或工作流,则它可能提供可行的替代方法。

**I actually used a slightly different formula, but it was on a work machine to which I don't have access at the moment, so I just grabbed this formula from a similar S.O. question. Any formula that will replace the first occurrence of a space with "%20" will work, the trick is to a) make sure the formula returns the original string unchanged if it does not have more spaces in it, and b) test, test, test. Create a view of your list that has the field you are trying to encode, plus the calculated fields, and see if you are getting the results you want.

**我实际上使用了一个稍微不同的公式,但它是在我目前无法访问的工作机器上,所以我只是从类似的S.O.抓住了这个公式。题。任何将用“%20”替换第一次出现的空格的公式都可以使用,诀窍是a)确保公式返回原始字符串不变,如果它没有更多的空格,并且b)测试,测试,测试。创建列表视图,其中包含您要编码的字段以及计算字段,并查看是否获得了所需的结果。

#3


so that the HTML link in the workflow produced email will actually not break off at the first space.

这样工作流程中生成的电子邮件中的HTML链接实际上不会在第一个空格中断。

The browser only does this if you have not enclosed your link in quotes

如果您没有在引号中包含链接,浏览器只会执行此操作

If you wrap the link in quotes, it does not cut off at the first space

如果用引号括起链接,它不会在第一个空格处切断

In a SharePoint Formula it would be:

在SharePoint公式中,它将是:

="""file:///Z:/data/This is our report.rpt"""

becuase two quotes are the SP escape notation to output a quote

因为两个引号是SP转义符号输出引号

#1


As far as I know there is no generic solution using the calculated-column syntax. The standard solution for this situation is using an ItemAdded (/ItemUpdated) event and initializing the field value from code.

据我所知,没有使用计算列语法的通用解决方案。这种情况的标准解决方案是使用ItemAdded(/ ItemUpdated)事件并从代码初始化字段值。

#2


I was able to solve this issue for my circumstances by using a series of calculated columns.

通过使用一系列计算列,我能够针对我的情况解决这个问题。

In the first calculated column (C1) I entered a formula to remove the first space, something like this**: =IF(ISNUMBER(FIND(" ",[Title])),REPLACE([Title],FIND(" ",[Title]),1,"%20"),[Title])

在第一个计算列(C1)中,我输入了一个公式来删除第一个空格,如下所示**:= IF(ISNUMBER(FIND(“”,[Title])),REPLACE([Title],FIND(“” ,[标题]),1, “%20”),[标题])

In the second Calculated column (C2) I used: =IF(ISNUMBER(FIND(" ",[C1])),REPLACE([C1],FIND(" ",[C1]),1,"%20"),[C1]).

在我使用的第二个计算列(C2)中:= IF(ISNUMBER(FIND(“”,[C1])),REPLACE([C1],FIND(“”,[C1]),1,“%20”) ,[C1])。

In my case, I wanted to encode up to four spaces, so I used 3 calculated columns (C1, C2, C3) in the same fashion and got the desired result.

在我的情况下,我想编码最多四个空格,所以我以相同的方式使用3个计算列(C1,C2,C3)并获得所需的结果。

This is not as efficient as using a single calculated column, but if SUBSTITUTE will not work in your SharePoint environment, and you cannot use an event handler or workflow, it may offer a workable alternative.

这不如使用单个计算列有效,但如果SUBSTITUTE在SharePoint环境中不起作用,并且您无法使用事件处理程序或工作流,则它可能提供可行的替代方法。

**I actually used a slightly different formula, but it was on a work machine to which I don't have access at the moment, so I just grabbed this formula from a similar S.O. question. Any formula that will replace the first occurrence of a space with "%20" will work, the trick is to a) make sure the formula returns the original string unchanged if it does not have more spaces in it, and b) test, test, test. Create a view of your list that has the field you are trying to encode, plus the calculated fields, and see if you are getting the results you want.

**我实际上使用了一个稍微不同的公式,但它是在我目前无法访问的工作机器上,所以我只是从类似的S.O.抓住了这个公式。题。任何将用“%20”替换第一次出现的空格的公式都可以使用,诀窍是a)确保公式返回原始字符串不变,如果它没有更多的空格,并且b)测试,测试,测试。创建列表视图,其中包含您要编码的字段以及计算字段,并查看是否获得了所需的结果。

#3


so that the HTML link in the workflow produced email will actually not break off at the first space.

这样工作流程中生成的电子邮件中的HTML链接实际上不会在第一个空格中断。

The browser only does this if you have not enclosed your link in quotes

如果您没有在引号中包含链接,浏览器只会执行此操作

If you wrap the link in quotes, it does not cut off at the first space

如果用引号括起链接,它不会在第一个空格处切断

In a SharePoint Formula it would be:

在SharePoint公式中,它将是:

="""file:///Z:/data/This is our report.rpt"""

becuase two quotes are the SP escape notation to output a quote

因为两个引号是SP转义符号输出引号