111,126
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
bool result = AddMoney();
if (result == true)
{
Console.WriteLine("充值成功");
}
else
{
Console.WriteLine("充值失败");
}
Console.ReadLine();
}
private static bool AddMoney()
{
string num;//输入的字符串
int position;//“#”在地址中的索引
string handsetNum="";//手机号
Console.Write("请输入充值卡号#充值卡密码#充值的手机号码:");
num = Console.ReadLine();
position = num.LastIndexOf("#");
if (position > 0)
{
//提取手机号
handsetNum = num.Substring(position);
}
else
{
Console.Write("请正确输入:");
}
Console.WriteLine("你要为{0}充入话费?确认请按1,取消请按任意键:",handsetNum);
string command = Console.ReadLine();
//char key = Console.ReadKey();
//if (key == 49) //数字键'1'的ASCII码为49
//{
// Console.WriteLine("冲值成功!");
//}
//else
//{
// Console.WriteLine("您放弃了冲值!");
//}
return command == "1";
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Handset
{
class Program
{
static void Main(string[] args)
{
bool result = AddMoney();
if (result == true)
{
Console.WriteLine("充值成功");
}
else
{
Console.WriteLine("充值失败");
}
Console.ReadLine();
}
private static bool AddMoney()
{
string num;//输入的字符串
int position;//“#”在地址中的索引
string handsetNum="";//手机号
Console.Write("请输入充值卡号#充值卡密码#充值的手机号码:");
num = Console.ReadLine();
position = num.LastIndexOf("#");
if (position > 0)
{
//提取手机号
handsetNum = num.Substring(position);
}
else
{
Console.Write("请正确输入:");
}
Console.WriteLine("你要为{0}充入话费?确认请按1,取消请按任意键:",handsetNum);
string command = Console.ReadLine();
//char key = Console.ReadKey();
//if (key == 49) //数字键'1'的ASCII码为49
//{
// Console.WriteLine("冲值成功!");
//}
//else
//{
// Console.WriteLine("您放弃了冲值!");
//}
return command == "1";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1 {
class Program {
static void Main( string[] args ) {
bool result=AddMoney();
Console.WriteLine(result.ToString());
Console.ReadLine();
}
static bool AddMoney() {
//充值卡卡号#充值卡密码#充值的手机号码
Console.Write( "充值卡卡号#充值卡密码#充值的手机号码" );
string original = Console.ReadLine();
string mobile = Regex.Match( original, @"#\d{11}$" ).Value;
Console.WriteLine( "您要充值的手机号码为:" + mobile + "\r\n确认请按1,取消请按0" );
string command = Console.ReadLine();
return command == "1";
}
}
}