编写程序实现功能:从键盘输入一个字符串和一个字符,若字符串中含有该字符,则输出该字符在字符串中第一次出现的位置(下标值),否则输出“未出现”

解决方案 »

  1.   

    string str=Console.ReadLine();
    string str2=Console.ReadLine();
    if(str.IndexOf(str2)>=0)
    Console.Write(str.IndexOf(str2));或
    ConsoleKeyInfo cki = Console.ReadKey();
      

  2.   

    其实wuyq11大哥的已经是全部了
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace _1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入一个字符");
                char ch =Convert .ToChar ( Console.ReadLine());
                Console.WriteLine("请输入一串字符");
                string str = Console.ReadLine();
                int start=str.IndexOf(ch.ToString());
                if (start >= 0)
                {                Console.WriteLine(start );
                }
            }
        }
    }
      

  4.   

    #include<stdio.h>
    #define n 20
    void main()
    {
    int i=0,j=0;
    char str[n],str1;
    printf("请输入字符串:");
    gets(str);
    printf("请输入字符:");
    scanf("%c",&str1);
    while(str[i]!='\0')
    {
    if(str[i]==str1)
    {
    printf("下表值为:%d\n",i);
    j=1;
    break;
    }
    else i++;
    }
    if(j==0) printf(" 未出现!!\n");
    }