4个回答
展开全部
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();
}
}
{
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();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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();
}
/// <summary>
/// 删除字符串中的指定字符
/// </summary>
/// <param name="str">待删除字符串</param>
/// <param name="delchar">要删除的字符</param>
/// <returns></returns>
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;
}
/// <summary>
/// 删除字符串中的指定字符串
/// </summary>
/// <param name="str">待删除字符串</param>
/// <param name="delchar">要删除的字符串</param>
/// <returns></returns>
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;
}
/// <summary>
/// 转置输出
/// </summary>
/// <param name="str">要转置的字符串</param>
/// <returns></returns>
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();
}
}
}
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();
}
/// <summary>
/// 删除字符串中的指定字符
/// </summary>
/// <param name="str">待删除字符串</param>
/// <param name="delchar">要删除的字符</param>
/// <returns></returns>
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;
}
/// <summary>
/// 删除字符串中的指定字符串
/// </summary>
/// <param name="str">待删除字符串</param>
/// <param name="delchar">要删除的字符串</param>
/// <returns></returns>
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;
}
/// <summary>
/// 转置输出
/// </summary>
/// <param name="str">要转置的字符串</param>
/// <returns></returns>
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();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给你个简单的:
using System.Linq;
string text = "abcdefg";
string newText = new string(text.Replace("b","").ToCharArray().Reverse().ToArray());
using System.Linq;
string text = "abcdefg";
string newText = new string(text.Replace("b","").ToCharArray().Reverse().ToArray());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
删除何必要弄那麼麻烦,换个思路,用replace就OK了
然後转chararray,倒序输出即可
然後转chararray,倒序输出即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询