一道题不会写 求解 编写程序实现功能:从键盘输入一个字符串和一个字符,若字符串中含有该字符,则输出该字符在字符串中第一次出现的位置(下标值),否则输出“未出现” 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str=Console.ReadLine();string str2=Console.ReadLine();if(str.IndexOf(str2)>=0)Console.Write(str.IndexOf(str2));或ConsoleKeyInfo cki = Console.ReadKey(); 其实wuyq11大哥的已经是全部了 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 ); } } }} #include<stdio.h>#define n 20void 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");} 一SQL语句问题 求解C#调用C++指针的传参问题 如何遍历xml 为什么回车无效? 费解 已知SqlServer2000的表名,如何得到创建该表的SQL脚本? C#如何将一个数学表达式中变量和操作符分析出来? 在comboBox控件中怎样引用xml文件的节点 用vs在.net平台C#开发的一个Windows 程序安装完成出现这个 How to drag-drop a picture box? 现在C#程序员的工资怎么样啊?大家来讨论。 在一个form上要显示上千个文字应该用什么控件啊? 如何获取指定长度的文件流
string str2=Console.ReadLine();
if(str.IndexOf(str2)>=0)
Console.Write(str.IndexOf(str2));或
ConsoleKeyInfo cki = Console.ReadKey();
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 );
}
}
}
}
#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");
}