string 转换 char

hzg_1105 2008-07-17 08:56:58
string[] outs = content.Split(xxxx);
如上所示:我想将文章的内容接"[#下一页#]"转换成string数组
可Split只能支持string数组、char、char数组什么的
请高手帮帮忙
...全文
314 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
bindsang 2008-07-18
  • 打赏
  • 举报
回复
感觉楼说说的怎么都不像是字符串拆分,更像是查询分页的问题
hzg_1105 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 cndrip 的回复:]
写错了一个地方

C# codestring strValues = "这里是你具体内容";
string [] strList = strValues.Split("\[\#下一页\#\]".ToCharArray());
[/Quote]

我在7楼就说了```这个方法是不行的
cndrip 2008-07-17
  • 打赏
  • 举报
回复
写错了一个地方
string strValues = "这里是你具体内容";
string [] strList = strValues.Split("\[\#下一页\#\]".ToCharArray());

hzg_1105 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 only_endure 的回复:]
没看清楚你的意图,不过最好知道split的重载参数类型及返回类型,可以参考楼上.
[/Quote]

的确是我没有弄明白其中的参数

在此我检讨

问题倒是解决了`````谢谢骑蜗牛看星星和其它热心的朋友们
cndrip 2008-07-17
  • 打赏
  • 举报
回复
string strValues = "这里是你具体内容";
string [] strList = strValues.Split("\[\#下一页\#\]".ToCharArray());(xxxx);
hackztx 2008-07-17
  • 打赏
  • 举报
回复
多个字符用split来弄是不行的。。他只是把你的string分成char然后对char做循环。如果发现那么split
所以这个东西必须用正则来弄


MatchCollection mc = Regex.Matches(strvalues, @"(.*?)\[#下一页#\]");
foreach (Match m in mc)
{
string s = m.Groups[1].Value;
}
NekChan 2008-07-17
  • 打赏
  • 举报
回复
StringSplitOptions Enumeration

Member name Description
None The return value includes array elements that contain an empty string
RemoveEmptyEntries The return value does not include array elements that contain an empty string
hongqi162 2008-07-17
  • 打赏
  • 举报
回复
不赞同这样的写法
string [] strList = strValues.Split("yourtag".ToCharArray());



自己写个函数然后使用Substring来分割
NekChan 2008-07-17
  • 打赏
  • 举报
回复
如果是使用的.net framework1.1,就老老实实的使用substring来做了
一品梅 2008-07-17
  • 打赏
  • 举报
回复
没看清楚你的意图,不过最好知道split的重载参数类型及返回类型,可以参考楼上.
hzg_1105 2008-07-17
  • 打赏
  • 举报
回复
TO 4、5楼

有没有测试过?

转换成char数组后将按string的任何一个元素进行转换了

比如[#下一页#]

出现它都会分页

我现在要的是当出现[#下一页#]才分页
NekChan 2008-07-17
  • 打赏
  • 举报
回复
使用String.Split Method (String[], StringSplitOptions)
注意This method is new in the .NET Framework version 2.0.

示例代码:
// This example demonstrates the String() methods that use
// the StringSplitOptions enumeration.
using System;

class Sample
{
public static void Main()
{
string s1 = ",ONE,,TWO,,,THREE,,";
string s2 = "[stop]" +
"ONE[stop][stop]" +
"TWO[stop][stop][stop]" +
"THREE[stop][stop]";
char[] charSeparators = new char[] {','};
string[] stringSeparators = new string[] {"[stop]"};
string[] result;
// ------------------------------------------------------------------------------
// Split a string delimited by characters.
// ------------------------------------------------------------------------------
Console.WriteLine("1) Split a string delimited by characters:\n");

// Display the original string and delimiter characters.
Console.WriteLine("1a )The original string is \"{0}\".", s1);
Console.WriteLine("The delimiter character is '{0}'.\n",
charSeparators[0]);

// Split a string delimited by characters and return all elements.
Console.WriteLine("1b) Split a string delimited by characters and " +
"return all elements:");
result = s1.Split(charSeparators, StringSplitOptions.None);
Show(result);

// Split a string delimited by characters and return all non-empty elements.
Console.WriteLine("1c) Split a string delimited by characters and " +
"return all non-empty elements:");
result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// Split the original string into the string and empty string before the
// delimiter and the remainder of the original string after the delimiter.
Console.WriteLine("1d) Split a string delimited by characters and " +
"return 2 elements:");
result = s1.Split(charSeparators, 2, StringSplitOptions.None);
Show(result);

// Split the original string into the string after the delimiter and the
// remainder of the original string after the delimiter.
Console.WriteLine("1e) Split a string delimited by characters and " +
"return 2 non-empty elements:");
result = s1.Split(charSeparators, 2, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// ------------------------------------------------------------------------------
// Split a string delimited by another string.
// ------------------------------------------------------------------------------
Console.WriteLine("2) Split a string delimited by another string:\n");

// Display the original string and delimiter string.
Console.WriteLine("2a) The original string is \"{0}\".", s2);
Console.WriteLine("The delimiter string is \"{0}\".\n", stringSeparators[0]);

// Split a string delimited by another string and return all elements.
Console.WriteLine("2b) Split a string delimited by another string and " +
"return all elements:");
result = s2.Split(stringSeparators, StringSplitOptions.None);
Show(result);

// Split the original string at the delimiter and return all non-empty elements.
Console.WriteLine("2c) Split a string delimited by another string and " +
"return all non-empty elements:");
result = s2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
Show(result);

// Split the original string into the empty string before the
// delimiter and the remainder of the original string after the delimiter.
Console.WriteLine("2d) Split a string delimited by another string and " +
"return 2 elements:");
result = s2.Split(stringSeparators, 2, StringSplitOptions.None);
Show(result);

// Split the original string into the string after the delimiter and the
// remainder of the original string after the delimiter.
Console.WriteLine("2e) Split a string delimited by another string and " +
"return 2 non-empty elements:");
result = s2.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries);
Show(result);
}

// Display the array of separated strings.
public static void Show(string[] entries)
{
Console.WriteLine("The return value contains these {0} elements:", entries.Length);
foreach (string entry in entries)
{
Console.Write("<{0}>", entry);
}
Console.Write("\n\n");
}
}
verydeed 2008-07-17
  • 打赏
  • 举报
回复
问题不是很清楚。

如果想转换成char数组,可以用string.ToCharArray
hackztx 2008-07-17
  • 打赏
  • 举报
回复
    string strValues = "";
string [] strList = strValues.Split("yourtag".ToCharArray());
hzg_1105 2008-07-17
  • 打赏
  • 举报
回复
谁能告诉我怎么能将[#下一页#]转换成char类型

或者能将一段文字接[#下一页#]转换成string数组

twtetg 2008-07-17
  • 打赏
  • 举报
回复
出于回帖的惯性,顶你!!!
HW_zxc_005 2008-07-17
  • 打赏
  • 举报
回复
up

62,243

社区成员

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

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

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

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