当前位置:编程学习 > C#/ASP.NET >>

帮我用C#写一个程序?

编写一个程序段,接收一个长度大于4的字符串,并完成下列功能:
1)输出字符串的长度
2)输出字符串中第一次出现字母a的位置
3)在字符串的第4个字符后面插入子串“hello”,输出新字符串
4)将字符串“hello”替换为“world”,输出新字符串
5)以第三个字符为分隔符,讲字符串分离,并输出分离后的字符串 --------------------编程问答-------------------- --------------------编程问答-------------------- 别做帮凶。帮做作业 --------------------编程问答-------------------- - -!
length,indexof,replace,split这几个方法而已,还要帮写? --------------------编程问答-------------------- 楼主不能偷懒 --------------------编程问答-------------------- 是为了学校交差的? --------------------编程问答-------------------- --------------------编程问答-------------------- 一看就知道是作业,呵呵~ --------------------编程问答-------------------- 绝对是作业 这题目简单 我想帮LZ解决问题 但是 我不能做帮凶啊 --------------------编程问答-------------------- 应该是个面试题  --------------------编程问答-------------------- 看楼主头像就知道是学生了,自己对着课件慢慢学咯,题目都说得这么明白了,也不是很难的,呵呵,凡事都有第一次嘛 --------------------编程问答-------------------- 不要做帮凶啊  绝对是在偷懒 --------------------编程问答-------------------- 这个可以自己写 --------------------编程问答-------------------- 我自己写了一个、不知道是不是这样的、大家帮我看一下      

  
      static void Main()
        {
            string input;
            while (true)
            {
                input = Console.ReadLine();
                if (input.Length > 4) break;
            }
            Console.WriteLine("Length : {0}", input.Length);
            Console.WriteLine("a position is : {0}", input.IndexOf('a'));
            Console.WriteLine(input.Insert(4, "hello"));
            Console.WriteLine(input.Replace("hello", "world"));
            foreach (string s in input.Split(input[2]))
            {
                Console.Write("{0} ", s);
            }
            Console.WriteLine();
            


            Console.ReadKey();
        }

--------------------编程问答-------------------- 4)将字符串“hello”替换为“world”,输出新字符串
string s= input.Insert(4, "hello");
Console.WriteLine(s.Replace("hello", "world"));
--------------------编程问答-------------------- 支持,这个可以自己写 --------------------编程问答-------------------- 悲剧······ --------------------编程问答-------------------- 好难啊,不会。 --------------------编程问答--------------------
引用楼主 andrew67419 的回复:
编写一个程序段,接收一个长度大于4的字符串,并完成下列功能:
1)输出字符串的长度
2)输出字符串中第一次出现字母a的位置
3)在字符串的第4个字符后面插入子串“hello”,输出新字符串
4)将字符串“hello”替换为“world”,输出新字符串
5)以第三个字符为分隔符,讲字符串分离,并输出分离后的字符串


第一题,Length
第二题,IndexOf
第三题,Insert
第二题,Replace
第五题,Split --------------------编程问答-------------------- 我以前也做过这个。。。LZ步后尘了 --------------------编程问答--------------------
引用 13 楼 andrew67419 的回复:
我自己写了一个、不知道是不是这样的、大家帮我看一下  

  
  static void Main()
  {
  string input;
  while (true)
  {
  input = Console.ReadLine();
  if (input.Length > 4) break;
  }
  Console.WriteLine("Length : {0……

字面上看,你写的完全正确。 --------------------编程问答-------------------- 烂学校培养烂学生。 --------------------编程问答-------------------- .............这种小事也拿出来问   --------------------编程问答--------------------   没有人会                             --------------------编程问答--------------------
引用 21 楼 superdullwolf 的回复:
烂学校培养烂学生。


说的太好了!这么几乎是小儿科的东西,也在这里问一下。。。。你看吧,大家都只说,懒的跟你说代码,我也懒的说,问题太低级了,一点兴趣都没有。看书吧,孩子。。。 --------------------编程问答-------------------- 。。。帮我找个媳妇儿 --------------------编程问答--------------------             Console.WriteLine(strInput.Insert(4, "hello"));
            Console.WriteLine(strInput.Replace("hello", "world"));
这段貌似有问题 其他都很好啊! --------------------编程问答--------------------
引用 21 楼 superdullwolf 的回复:
烂学校培养烂学生。


烂学校是根本 --------------------编程问答--------------------
引用 18 楼 xx_mm 的回复:
引用楼主 andrew67419 的回复:
编写一个程序段,接收一个长度大于4的字符串,并完成下列功能:
1)输出字符串的长度
2)输出字符串中第一次出现字母a的位置
3)在字符串的第4个字符后面插入子串“hello”,输出新字符串
4)将字符串“hello”替换为“world”,输出新字符串
5)以第三个字符为分隔符,讲字符串分离,并输出分离后的字符串


第一题,Length……

+1 --------------------编程问答-------------------- 做作业的来了  --------------------编程问答-------------------- 汗、、、原来我们学校的都这么烂 、哥们、咱们快闪吧 。 --------------------编程问答-------------------- 太难了,不会 --------------------编程问答--------------------
引用 25 楼 hooverhuang 的回复:
。。。帮我找个媳妇儿


--------------------编程问答--------------------
引用 26 楼 chinesesword 的回复:
Console.WriteLine(strInput.Insert(4, "hello"));
  Console.WriteLine(strInput.Replace("hello", "world"));
这段貌似有问题 其他都很好啊!

我试试 --------------------编程问答--------------------
static void Main(string[] args)
        {
            string strInput;
            while (true)
            {
                strInput = Console.ReadLine();
                if (strInput.Length > 4)
                {
                    break;
                }
            }
            Console.WriteLine("字符串长度:{0}", strInput.Length);
            Console.WriteLine("a的位置:{0}", strInput.IndexOf('a')+1);
            string str1 = strInput.Insert(4, "hello");
            Console.WriteLine(str1);
            string str2 = str1.Replace("hello", "world");
            Console.WriteLine(str2);
            string[] splitString = str2.Split(str2[2]);
            Console.WriteLine("{0} {1}",splitString[0],splitString[1]);
            Console.ReadLine();
        }
要的结果是这样吗? --------------------编程问答--------------------

static void Main(string[] args)
        {
            string strInput;
            while (true)
            {
                strInput = Console.ReadLine();
                if (strInput.Length > 4)
                {
                    break;
                }
            }
            Console.WriteLine("字符串长度:{0}", strInput.Length);
            Console.WriteLine("a的位置:{0}", strInput.IndexOf('a')+1);
            string str1 = strInput.Insert(4, "hello");
            Console.WriteLine(str1);
            string str2 = str1.Replace("hello", "world");
            Console.WriteLine(str2);
            string[] splitString = str2.Split(str2[2]);
            Console.WriteLine("{0} {1}",splitString[0],splitString[1]);
            Console.ReadLine();
        }
--------------------编程问答-------------------- 杯具了... --------------------编程问答-------------------- --------------------编程问答-------------------- 学生作业的可能性较大。
再看接铁律的确无语。 --------------------编程问答--------------------
引用 8 楼 peng2739956 的回复:
绝对是作业 这题目简单 我想帮LZ解决问题 但是 我不能做帮凶啊

觉得是作业 而不像面试题 --------------------编程问答-------------------- if(you==Student)
{
   out;
}
else
{
   next;
}
--------------------编程问答--------------------
引用 21 楼 superdullwolf 的回复:
烂学校培养烂学生。

+1 --------------------编程问答--------------------  笑死我了!!!lz。。。。 --------------------编程问答-------------------- --------------------编程问答-------------------- 第一,绝对不帮忙。
第二,悲叹。 --------------------编程问答-------------------- 赞成,什么就要帮.最基本的. --------------------编程问答--------------------
引用 39 楼 xianfengxyz 的回复:
引用 8 楼 peng2739956 的回复:
绝对是作业 这题目简单 我想帮LZ解决问题 但是 我不能做帮凶啊

觉得是作业 而不像面试题

这作面试题我现在就可以毕业了 --------------------编程问答-------------------- 建议楼主详细查看msdn的string介绍 --------------------编程问答-------------------- 这丫的当CSDN的都是免费劳动力! --------------------编程问答-------------------- 作业也问点难点的,这也太那个什么了。。。。 --------------------编程问答-------------------- 哈哈  楼主有发展啊   --------------------编程问答-------------------- 作业题…… --------------------编程问答--------------------
引用 21 楼 superdullwolf 的回复:
烂学校培养烂学生。



对于一个自学的人来说,找一所好的培训机构的确很难。
我也想去,可是哪有呢? --------------------编程问答-------------------- 要自己写作业 --------------------编程问答-------------------- 楼主来找作业劳动力 呵呵 自己做吧 还比较简单的吧 --------------------编程问答-------------------- 确实有点懒了啊

msdn帮助文档里都有源码的哦。。。 --------------------编程问答-------------------- --------------------编程问答-------------------- 写过之后,运行一下,就知道对错了!希望我的回答,能够对你有帮助S --------------------编程问答-------------------- --------------------编程问答-------------------- 楼主自己动手试试 --------------------编程问答-------------------- - -
字符串的处理LZ都不知道啊LZ.... --------------------编程问答-------------------- 这个确实是简单了点 看看msdn上关于string的帮助 你就能解决了 --------------------编程问答--------------------  static void Main()
        {
            string strInput;
            while (true)
            {
                strInput = "abcd";
                if (strInput.Length > 4)
                {
                    break;
                }
            }      
            
            string[] a =new string[5]{"1","2","3","4","5"};
            
            Console.WriteLine("字符串长度:{0}", strInput.Length);
            Console.WriteLine("a的位置:{0}", strInput.IndexOf('a') + 1);
            string str1 = strInput.Insert(4, "hello");
            Console.WriteLine(str1);
            string str2 = str1.Replace("hello", "world");
            Console.WriteLine(str2);
            string[] splitString = str2.Split(str2[2]);
            Console.WriteLine("{0} {1}", splitString[0], splitString[1]);
            Console.ReadLine();
        } --------------------编程问答-------------------- 杯具帝~~~ --------------------编程问答-------------------- 看一下文档什么都有了……
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,