编写程序:从一个字符串中删除指定的字符。并将结果倒序输出 注意!!是C#!!!!是Visual C#.net!!!

在线坐等答案!!!求大神指导~~~
2024-11-30 06:25:30
推荐回答(4个)
回答1:

class Program
{
static void Main(string[] args)
{
Console.WriteLine("输入目标字符串:");
string ObjString = Console.ReadLine();
Console.WriteLine("输入要删除的字符串:");
string DelString = Console.ReadLine();
Console.WriteLine(ReturnResultStringMethod(ObjString,DelString));
Console.ReadLine();
}
private static string ReturnResultStringMethod(string ObjString, string DelString)
{

StringBuilder sb = new StringBuilder();
string tempString = ObjString.Substring(0, ObjString.IndexOf(DelString)) + ObjString.Substring(ObjString.IndexOf(DelString) + DelString.Length);

foreach (char c in tempString)
{
sb.Insert(0, c);
}
return sb.ToString();
}
}

回答2:

vs2005测试通过,楼主试一下
using System;
using System.Collections.Generic;
using System.Text;

namespace stringDel
{
class Program
{
static void Main(string[] args)
{
string test = "EWRTYUGHJKHJTYUIFGHJK";
test = delString(test, 'Y');
test = revortString(test);
Console.WriteLine(test);
Console.Read();
}
///


/// 删除字符串中的指定字符
///

/// 待删除字符串
/// 要删除的字符
///
private static string delString(string str, char delchar)
{
while (str.IndexOf(delchar) != -1)
{
int count = str.IndexOf(delchar);
str = str.Remove(str.IndexOf(delchar), 1);
}
return str;
}
///
/// 删除字符串中的指定字符串
///

/// 待删除字符串
/// 要删除的字符串
///
private static string delString(string str, string delstring)
{
while (str.IndexOf(delstring) != -1)
{
int count = str.IndexOf(delstring);
str = str.Remove(str.IndexOf(delstring), delstring.Length);
}
return str;
}
///
/// 转置输出
///

/// 要转置的字符串
///
private static string revortString(string str)
{
char[] mid = str.ToCharArray();
StringBuilder sb = new StringBuilder();
for (int i = mid.Length - 1; i >= 0; i--)
{
sb.Append(mid[i]);
}
return sb.ToString();
}
}
}

回答3:

给你个简单的:
using System.Linq;

string text = "abcdefg";
string newText = new string(text.Replace("b","").ToCharArray().Reverse().ToArray());

回答4:

删除何必要弄那麼麻烦,换个思路,用replace就OK了
然後转chararray,倒序输出即可