搜了一早上不满意,字符串分组问题,请高手

yooono 2006-07-20 09:22:34
"hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;"
关于这个字符串,我要按照";=;"分割成一个数组.

在net1.*中该如何解决?
用正则如何解决?
...全文
394 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eddie005 2006-07-20
  • 打赏
  • 举报
回复
string tmp = "hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;" ;
System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(";=;");
string[] results = rg.Split(tmp);
Ivony 2006-07-20
  • 打赏
  • 举报
回复
用证则不就完了?

new Regex( ";=;" ).Split( "hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;" )
myminimouse 2006-07-20
  • 打赏
  • 举报
回复
up
zhuxiaojun2002 2006-07-20
  • 打赏
  • 举报
回复
string s = "12121aaa342aaa6456aaa75";
String pattern = "aaa";
String[] result = Regex.Split(s, pattern);

int i=0;
foreach(String str in result)
{
Console.WriteLine("result[{0}]={1}", i, str);
i ++;
}
Console.ReadLine();
yooono 2006-07-20
  • 打赏
  • 举报
回复
怎么写个正则把要提取的提出来做成数组呢?
yooono 2006-07-20
  • 打赏
  • 举报
回复
你要提取的string
===
我要提取的东西不知道...
warfen 2006-07-20
  • 打赏
  • 举报
回复
楼主是不是要获取 "-=-" 与 ";=;"之间的内容?
string pattern = "-=-(?<1>[^~]*?);=;";
Regex myEx = new Regex(pattern);
MatchCollection mc = myEx.Matches(你要提取的string);
string strResult = "";
foreach(Match m in mc)
{
strResult + = m.Groups["1"].Value;
}
return strResult;
  • 打赏
  • 举报
回复
按照你的需求写出来的,觉得怪怪的

<%@ page language="vb" %>
<script runat="server">
sub page_load(sender as object,e as eventargs)

dim a as string="hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;"
a=a.substring(0,a.length-3)
dim b() as string=a.split(";=;")
dim i as integer
for i=0 to b.length-1
response.write(b(i) & "<br>")
next i

end sub
</script>

运行结果

hfinput1-=-测试1
=
hfinput2-=-sd
=
hfinput3-=-2006-07-07
=
hfinput4-=-2006-07-21
=
hfinput5-=-速度办理
=
hfselect1-=--1
job_2006 2006-07-20
  • 打赏
  • 举报
回复
yooono 2006-07-20
  • 打赏
  • 举报
回复
Regex r = new Regex("(;=;)");
string[] stt = r.Split(this.txtvalue.Value.Trim());
yooono 2006-07-20
  • 打赏
  • 举报
回复
要严格匹配是不是用正则?
yooono 2006-07-20
  • 打赏
  • 举报
回复
分解出来如下:{Length=25}
[0]: "hfinput1-"
[1]: "-测试1马"
[2]: ""
[3]: ""
[4]: "hfinput2-"
[5]: "-马丹阳"
[6]: ""
[7]: ""
[8]: "hfinput3-"
[9]: "-2006-07-07"
[10]: ""
[11]: ""
[12]: "hfinput4-"
[13]: "-2006-07-21"
[14]: ""
[15]: ""
[16]: "hfinput5-"
[17]: "-速度办理"
[18]: ""
[19]: ""
[20]: "hfselect1-"
[21]: "--1"
[22]: ""
[23]: ""
[24]: ""
zorou_fatal 2006-07-20
  • 打赏
  • 举报
回复
Sorry

Try

string sourcestring="hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;"

string gap_array=";=;";

string[] target_array=soucestring.split(gap_array.ToCharArray());
anheizhizi 2006-07-20
  • 打赏
  • 举报
回复
Convert.ToCharArray 是哪里的?
anheizhizi 2006-07-20
  • 打赏
  • 举报
回复
replace() - spilt()
zorou_fatal 2006-07-20
  • 打赏
  • 举报
回复
try

string sourcestring="hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;"

string[] target_array=soucestring.split(Convert.ToCharArray(";=;"));
yooono 2006-07-20
  • 打赏
  • 举报
回复
不要用replace()
glaciall 2006-07-20
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Net;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
public Class1(){
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
string text = "hfinput1-=-测试1;=;hfinput2-=-sd玛勒格彼德,三点丫的狗太阳的;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;";
Console.WriteLine(GetVal(text, "hfinput2"));
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
}
}
public static string GetVal(string input, string param)
{
Match match = Regex.Match(input, @"\W*" + param + "-=-" + "([^;]*)");
if (match.Success)
{
return match.Groups[1].Value;
}
return "";
}
}
}
glaciall 2006-07-20
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Net;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
public Class1(){
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
string text = "hfinput1-=-测试1;=;hfinput2-=-sd;=;hfinput3-=-2006-07-07;=;hfinput4-=-2006-07-21;=;hfinput5-=-速度办理;=;hfselect1-=--1;=;";
Console.WriteLine(GetVal(text, "hfinput1"));
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
}
}
public static string GetVal(string input, string param)
{
Match match = Regex.Match(input, @"\W*" + param + "-=-" + "([^;]*)");
if (match.Success)
{
return match.Groups[1].Value;
}
return "";
}
}
}
glaciall 2006-07-20
  • 打赏
  • 举报
回复
玛勒格彼德.
加载更多回复(7)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧