寻找从源字符串多个索引 [英] Finding multiple indexes from source string

查看:153
本文介绍了寻找从源字符串多个索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我需要做的String.IndexOf(),我需要得到指标的阵列从源字符串。

有没有简单的方法来获得指标的阵列?

在问这个问题,我用Google搜索了很多,但还没有找到简单的解决方案来解决这个简单的问题。

解决方案

  VAR指标的影响=PRASHANT.MultipleIndex('A');

//扩展方法的类
    公共静态类扩展
    {
         静态INT I = 0;

         公共静态INT [] MultipleIndex(此字符串的StringValue,CHAR chChar)
         {

           VAR指标的影响从rgChar =中的StringValue
                        其中,rgChar == chChar和放大器;&安培;我!= StringValue.IndexOf(rgChar,I + 1)
                        选择新{指数= StringValue.IndexOf(rgChar,I + 1),Increament =(I = I + StringValue.IndexOf(rgChar))};
            I = 0;
            返回indexs.Select(P => p.Index).ToArray< INT>();
          }
    }
 

Basically I need to do String.IndexOf() and I need to get array of indexes from the source string.

Is there easy way to get array of indexes?

Before asking this question I have Googled a lot, but have not found easy solution to solve this simple problem.

解决方案

    var indexs = "Prashant".MultipleIndex('a');

//Extension Method's Class
    public static class Extensions
    {
         static int i = 0;

         public static int[] MultipleIndex(this string StringValue, char chChar)
         {

           var indexs = from rgChar in StringValue
                        where rgChar == chChar && i != StringValue.IndexOf(rgChar, i + 1)
                        select new { Index = StringValue.IndexOf(rgChar, i + 1), Increament = (i = i + StringValue.IndexOf(rgChar)) };
            i = 0;
            return indexs.Select(p => p.Index).ToArray<int>();
          }
    }

这篇关于寻找从源字符串多个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆