Need to get a string after a “word” in a string in c#

前端 未结 7 1589
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 13:45

i\'m having a string in c# for which i have to find a specific word \"code\" in the string and have to get the remaining string after the word \"code\".

The string i

相关标签:
7条回答
  • 2020-12-08 14:08
    string founded = FindStringTakeX("UID:   994zxfa6q", "UID:", 9);
    
    
    string FindStringTakeX(string strValue,string findKey,int take,bool ignoreWhiteSpace = true)
        {
            int index = strValue.IndexOf(findKey) + findKey.Length;
    
            if (index >= 0)
            {
                if (ignoreWhiteSpace)
                {
                    while (strValue[index].ToString() == " ")
                    {
                        index++;
                    }
                }
    
                if(strValue.Length >= index + take)
                {
                    string result = strValue.Substring(index, take);
    
                    return result;
                }
    
    
            }
    
            return string.Empty;
        }
    
    0 讨论(0)
提交回复
热议问题