【问题标题】:Counting the occurrences of a character in a string计算字符串中某个字符的出现次数
【发布时间】:2017-10-09 01:48:40
【问题描述】:

在 XSLT 1.0 中,我有一个节点,其值具有特殊字符、数字、字母。由此,我需要计算特定字符的数量。考虑下面的节点。

<sample>abc.123.@#$,def$%^123.kl.lo</sample>

在此,我需要单独计算小数点。所以,结果应该是4。请说出你的想法。以下是我尝试过的几个代码。

<xsl:value-of select="count(/*/*/sample[contains(., '.')]) "/>

<xsl:value-of select="count(//sample[.])"/>

【问题讨论】:

  • Linq?例如。 string source = ...; int count = source.Count(c =&gt; c == '.');
  • 你尝试了什么?什么?
  • 是的,我尝试了以下这些。
  • @NareshArvind:编辑您的问题并展示您的尝试

标签: c# .net xml xslt xsd


【解决方案1】:

检查此代码您的问题解决了

string-length(//sample) - string-length(translate(//sample, '.', ''))

【讨论】:

  • 谢谢。这个答案有帮助,我的问题得到了解决。
猜你喜欢
  • 2010-11-12
  • 2013-12-25
  • 1970-01-01
  • 2013-02-24
  • 1970-01-01
  • 1970-01-01
  • 2014-04-24
相关资源
最近更新 更多