我需要从字符串中删除'Hundred'如果单词'Hundred'后面跟着千或者或Lakh。 如何做到这一点。任何帮助将非常感激。 我尝试过:Hi All,I have string ,str=Fourty Four Thousand Hundred Sixty Five Dirhams and Twenty Two FilsI need to remove 'Hundred' from string if the word 'Hundred' is followed by Thousand or Hundred or Lakh.How to do this.Any help will be really appreciated.What I have tried:if (Regex.IsMatch(str, "Hundred")) { // check if it is followed by thousand or Hundred or Lakh //remove it if it is followed by thousand or Hundred or Lakh }推荐答案如果你的意思是如果这个词'Hundred'跟随千或......在你的例子中,然后试试这个:If you mean "if the word 'Hundred" follows Thousand or ..." as in your example, then try this:(?<=(Thousand|Hundred|Lakh)\s+)Hundred删除单词:To remove the word:public static Regex remove = new Regex("(?<=(Thousand|Hundred|Lakh)\\s+)Hundred", RegexOptions.Compiled);...string result = remove.Replace(InputText,""); 如果你想玩使用正则表达式,获取 Expresso 的副本[ ^ ] - 它是免费的,它检查并生成正则表达式。If you want to play with regexes, get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.如果你懒得学习正则表达式,这是另一个不太优雅的解决方案:If You are too lazy to learn regex , here is another not so elegant solution :string Check(string str){string s = str.Replace(" ","").Replace("Hundred","*");string [] s1 = s.Split('*');if(s1[1].Contains("Thousand") || s1[1].Contains("Hundred") || s1[1].Contains("Lakh")){str = str.Replace("Hundred","");}return str;} 字符串检查后, 字如果后面是单词, 千或者或Lakh。 一切顺利, $ b $bŽeljkoPerićAfter string check,word Hundred will be removed if it is followed by words,Thousand or Hundred or Lakh.All the best,Željko Perić 这篇关于删除一个字符串,如果它后跟C#中的另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-31 19:59