c#字符串操作 [英] c# string manipulation

查看:111
本文介绍了c#字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个字符串SSSEERRTADEEE写一个程序,输出以下给定字符串的方式:S3E2R2T1A1D1E3





请问逻辑是什么在c#上面的问题C#。希望任何人都必须给我解决方案......等待你的回复......

解决方案

你可以使用下面的代码: br />


 私人  static   void  GetCharCountInString()
{
const string strOriginal = SSSEERRTADEEE;
string strNew = string .Empty;
int index = 0 ;
char [] chararray = strOriginal.ToCharArray();


for (index = 0 ; index < chararray.Length; index ++)
{
int charCount = 1 ;
int firstindex = index;
int flag = 0 ;

while (index!= strOriginal.Length - 1 & flag = = 0
{
if (chararray [index] .CompareTo(chararray) [index + 1 ])== 0
{
charCount ++;
index ++;
flag = 0 ;
}
其他
{
flag = 1 ;
}
}

strNew + = chararray [firstindex] .ToString(CultureInfo.InvariantCulture)+
charCount.ToString(CultureInfo.InvariantCulture);
}

Console.WriteLine( 原文:{0} \ n新:{1},strOriginal,strNew);
}





快乐编码:)


  string  s =  //   ...  

// ...

if (s == SSSEERRTADEEE
s = S3E2R2T1A1D1E3;

// ...: - )





它应该给你以下想法:如果你提供了输入和输出数据的一些例子,这并不意味着你提出了问题。



这个问题没有任何意义。



祝你好运,

-SA

given a string SSSEERRTADEEE write a program to output the following way to given string:S3E2R2T1A1D1E3


please what will be the logic to above probl C# in c#.Hope anyone must give me the solution...am waiting for your reply...

解决方案

You can use the code below:

private static void GetCharCountInString()
        {
            const string strOriginal = "SSSEERRTADEEE";
            string strNew = string.Empty;
            int index = 0;
            char[] chararray = strOriginal.ToCharArray();


            for (index = 0; index < chararray.Length; index++)
            {
                int charCount = 1;
                int firstindex = index;
                int flag = 0;

                while (index != strOriginal.Length - 1 & flag == 0)
                {
                    if (chararray[index].CompareTo(chararray[index + 1]) == 0)
                    {
                        charCount++;
                        index++;
                        flag = 0;
                    }
                    else
                    {
                        flag = 1;
                    }
                }

                strNew += chararray[firstindex].ToString(CultureInfo.InvariantCulture) +
                          charCount.ToString(CultureInfo.InvariantCulture);
            }

            Console.WriteLine("Original : {0}\n New : {1}", strOriginal, strNew);
        }



Happy Coding :)


string s = // ...

// ...

if (s == "SSSEERRTADEEE")
    s = "S3E2R2T1A1D1E3";

//... :-)



It should give you the following idea: if you provided some example of data on input and output, it does not mean you formulated the problem.

The question does not really make any sense.

Good luck,

—SA


这篇关于c#字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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