刚结100分,再来100分, 还是字符串截取问题,大家进来讨论下,UP也给分~~
最近搞了个辅助工具,上一任程序走了,所以我接到这个弄的很不爽,呵呵~~加上本人比较菜(看正则跟乱码差不多那种),所以麻烦大家了~
不多说了,下面说问题:
1.ageStart = "1981年05月19日 ";
问题描述:取出的出生日期就是上面这样子,我需要datatime类型 如1981-05-19
2.str = "软件工程师,高级软件工程师,GAY... " //目标职能
问题描述:每个职位都是用 ", "分开的最后一个没有,分别取出来
3.edu = "1998/09--2001/07玉林师院计算机科学与技术 本科
软件工程 数据结构 系统结构 网络安全等 " //教育经历
问题描述: 这个上周弄过,前面时间,学校,专业能弄出来,但是专业和学历之间有空格,还有就是要下面的专业课名称
我对分不是很在乎,都给你们也行,呵呵,大家多费心了,上周帮忙的兄弟在这里谢谢了,祝大家中秋快乐~~
[解决办法]
sf
[解决办法]
jf
[解决办法]
1.String.Format就可以解决
日期 {0:D} 2006年11月25日
日期 {0:d} 2006-11-25
2.String[] querySplit = new String[x];
Char[] charSeparators = new Char[] { ', ' };
querySplit = strQuery.Split(charSeparators, StringSplitOptions.None);
3.没看明白
[解决办法]
up
学习
[解决办法]
1.String.format
2.string.replace
3.string.Split
具体怎么做看自己的要求,给你点例子:
1.string.format
// This code example demonstrates the String.Format() method.
// Formatting for this example uses the "en-US " culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
// Store the output of the String.Format method in a string.
string s = " ";
Console.Clear();
// Format a negative integer or floating-point number in various ways.
Console.WriteLine( "Standard Numeric Format Specifiers ");
s = String.Format(
"(C) Currency: . . . . . . . . {0:C}\n " +
"(D) Decimal:. . . . . . . . . {0:D}\n " +
"(E) Scientific: . . . . . . . {1:E}\n " +
"(F) Fixed point:. . . . . . . {1:F}\n " +
"(G) General:. . . . . . . . . {0:G}\n " +
" (default):. . . . . . . . {0} (default = 'G ')\n " +
"(N) Number: . . . . . . . . . {0:N}\n " +
"(P) Percent:. . . . . . . . . {1:P}\n " +
"(R) Round-trip: . . . . . . . {1:R}\n " +
"(X) Hexadecimal:. . . . . . . {0:X}\n ",
-123, -123.45f);
Console.WriteLine(s);
// Format the current date in various ways.
Console.WriteLine( "Standard DateTime Format Specifiers ");
s = String.Format(
"(d) Short date: . . . . . . . {0:d}\n " +
"(D) Long date:. . . . . . . . {0:D}\n " +
"(t) Short time: . . . . . . . {0:t}\n " +
"(T) Long time:. . . . . . . . {0:T}\n " +
"(f) Full date/short time: . . {0:f}\n " +
"(F) Full date/long time:. . . {0:F}\n " +
"(g) General date/short time:. {0:g}\n " +
"(G) General date/long time: . {0:G}\n " +
" (default):. . . . . . . . {0} (default = 'G ')\n " +
"(M) Month:. . . . . . . . . . {0:M}\n " +
"(R) RFC1123:. . . . . . . . . {0:R}\n " +
"(s) Sortable: . . . . . . . . {0:s}\n " +
"(u) Universal sortable: . . . {0:u} (invariant)\n " +
"(U) Universal sortable: . . . {0:U}\n " +
"(Y) Year: . . . . . . . . . . {0:Y}\n ",
thisDate);
Console.WriteLine(s);
// Format a Color enumeration value in various ways.
Console.WriteLine( "Standard Enumeration Format Specifiers ");
s = String.Format(
"(G) General:. . . . . . . . . {0:G}\n " +
" (default):. . . . . . . . {0} (default = 'G ')\n " +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n " +
"(D) Decimal number: . . . . . {0:D}\n " +
"(X) Hexadecimal:. . . . . . . {0:X}\n ",
Color.Green);
Console.WriteLine(s);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G ')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G ')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal sortable: . . . Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G ')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
2.string.replace
using System;
public class ReplaceTest {
public static void Main() {
string errString = "This docment uses 3 other docments to docment the docmentation ";
Console.WriteLine( "The original string is:{0} '{1} '{0} ", Environment.NewLine, errString);
// Correct the spelling of "document ".
string correctString = errString.Replace( "docment ", "document ");
Console.WriteLine( "After correcting the string, the result is:{0} '{1} ' ",
Environment.NewLine, correctString);
}
}
3.String.Split 方法
using System;
public class SplitTest {
public static void Main() {
string words = "this is a list of words, with: a bit of punctuation. ";
string [] split = words.Split(new Char [] { ' ', ', ', '. ', ': '});
foreach (string s in split) {
if (s.Trim() != " ")
Console.WriteLine(s);
}
}
}
[解决办法]
LZ分还真多 有空学学正则吧 不是很难
[解决办法]
你把专业课名放在一个字符串中
用string.Split( ' ')放在字符数组中就完事了
[解决办法]
jf
[解决办法]
string.Split
[解决办法]
1.String.Format就可以解决
日期 {0:D} 2006年11月25日
日期 {0:d} 2006-11-25
2.String[] querySplit = new String[x];
Char[] charSeparators = new Char[] { ', ' };
querySplit = strQuery.Split(charSeparators, StringSplitOptions.None);
for(int i =0;i <querySplit.length-1;i++)
{
}
[解决办法]
对于第1个问题,按我的理解,楼主要的结果应该是这样的吧
string ageStart = "1981年05月19日 ";
DateTime dt = DateTime.ParseExact(ageStart, "yyyy年MM月dd日 ", null);
[解决办法]
第3个问题也没有看明白
[解决办法]
jf
[解决办法]
- -!这顶高帽戴不得。。。
由于一些个人原因,最近不想回正则问题的具体实现,给你说下问题的关键吧
1998/09--2001/07玉林师院计算机科学与技术 本科
软件工程 数据结构 系统结构 网络安全等
前面的日期1998/09--2001/07可以直接匹配出来,学历根据前后空格,或是因为学历只有那几种,用“|”拼接一个正则也可以取出来,最后的课程一起取出来就是了,如有需要按空格Split就行了,以上这些可以一个正则做到,没任何难度
比较麻烦的是学校和专业,这个需要楼主给出一定的规则来进行区分,比如说列举学校的后缀,就楼主现在所给例子来看,这个规则不给出,那是没法对这两部分进行区分的
当然,也不要把问题局限在正则上,是否能从源字符串获取时的格式上入手,限定一定的格式
[解决办法]
就冲你顶也给分来的,哈哈
up
[解决办法]
up
[解决办法]
jf
[解决办法]
Ding
[解决办法]
辅助工具?是采集器吧。。。
[解决办法]
楼主不厚道 一点分都不给人家
[解决办法]
学习 帮顶!
[解决办法]
学习中,帮顶!
[解决办法]
LZ上周帖的问题怎么解决的?
[解决办法]
//////////////////////////////////////////////////////////////////////////////
最简单,最安全,最实用:
1.
Convert.ToDateTime( "1981年05月19日 ");
2.
string[] array = "软件工程师,高级软件工程师,GAY... " .Split( ', ');
3.所有专业课名称(不知道是你想要的不)
string str = "1998/09--2001/07玉林师院计算机科学与技术 本科 软件工程 数据结构 系统结构 网络安全等 ";
string[] strs = str.Substring(str.IndexOf( ' ')).Trim().Split();
foreach(string s in strs)
Console.WriteLine(s);
///////////////////////////////////////////////////////////////////////////////
------解决方案--------------------
UP
[解决办法]
过客不出手 我来写个试试- -!
@ "(? <date> \d{4}/\d{2}--\d{4}/\d{2})(? <un> [^\s]*?(院|大学|校))(? <sp> [^\s]*)\s*(? <kn> 本科|大专)\s*(? <cl> [\s\S]*?)等 "
Group[ "date "] 日期
Group[ "un "] 学校 名称不包括院 大学或校字 则整个匹配会失败
Group[ "sp "] 专业
Group[ "kn "] 学历
Group[ "cl "] 课程
Group[ "cl "] 取出后再split by ' '
[解决办法]
写下吧,winform下的测试代码
string yourStr = ............;
Match m = Regex.Match(yourStr, @ "(? <time> \d{4}/\d{2}--\d{4}/\d{2})(? <school> .*?(?:院|大学|校))(? <major> \S+)\s+(? <Education> \S+)\s+(? <curriculum> .*) ", RegexOptions.IgnoreCase);
if (m.Success)
{
MessageBox.Show(m.Groups[ "time "].Value);
MessageBox.Show(m.Groups[ "school "].Value);
MessageBox.Show(m.Groups[ "major "].Value);
MessageBox.Show(m.Groups[ "Education "].Value);
MessageBox.Show(m.Groups[ "curriculum "].Value);
}
[解决办法]
都是比较简单的字符串操作把.
[解决办法]
学习.....
[解决办法]
看不太懂,学习了...
[解决办法]
string edu = @ "1998/09--2001/07玉林师院计算机科学与技术 本科
软件工程 数据结构 系统结构 网络安全等 ";
Match m = Regex.Match(edu, @ "(? <time> \d{4}/\d{2}--\d{4}/\d{2})(? <school> .*?(?:院|大学|校))(? <major> \S+)\s+(? <Education> \S+)\s+(? <curriculum> .*) ", RegexOptions.IgnoreCase);
if (m.Success)
{
MessageBox.Show(m.Groups[ "time "].Value);
MessageBox.Show(m.Groups[ "school "].Value);
MessageBox.Show(m.Groups[ "major "].Value);
MessageBox.Show(m.Groups[ "Education "].Value);
MessageBox.Show(m.Groups[ "curriculum "].Value);
}
[解决办法]
Study...
[解决办法]
分格出来应该可以吧,例子
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string aStr = "a,db,dc,dd ";
string [] split = Regex.Split(aStr, ",d ");
foreach (string s in split)
{
Console.WriteLine(s);
}
}
}
/* 程序输出:
a
b
c
d
*/
[解决办法]
up
[解决办法]
TRY
Match m = Regex.Match(edu, @ "(? <time> \d{4}/\d{2}--(?:\d{4}/\d{2}|至今))(? <school> .*?(?:院|大学|校))(? <major> \S+)\s+(? <Education> \S+)\s+(? <curriculum> .*) ",
[解决办法]
looklook