如果可能的话,我想要一些关于这个电子邮件解析器的帮助。
这段代码有所有正确的声明和初始化,但我不确定我在哪里搞砸了这个循环:
while ( getline( fin, lines ) )
{
for ( int i = 0; i < lines.length( ); i++ )
{
if ( lines[ i ] == '@' )
{
for ( s = i; s < lines.length( ); s-- )
{
if ( s < 0 )
{
break;
}
if ( validChar( lines[ s ] ) == false )
{
break;
}
} //for
for ( e = i; e > lines.length( ); e++ )
{
if ( e == lines.length( ) )
{
break;
}
if ( validChar( lines[ e ] ) == false )
{
break;
}
if ( lines[ e ] == '.' )
{
hasDot = true;
}
} // for
anEmail = lines.substr( s, e );
cout << anEmail << endl;
}
} // if
} // while
这是为了功能:
bool validChar( char a )
{
bool result = false;
if ( a >= 'A' && a <= 'Z' || a >= 'a' && a <= 'z' || a >= '0' && a <= '9' || a == '.' || a == '-' || a == '+' )
{
result = true;
}
return result;
}
编辑:一个测试用例是文本文件中的这个字符串“这是一个包含 DummyTest@my.test 和其他一些测试文本的电子邮件文件”,我想要这个“DummyTest@my.test”,我只是得到这个“@my.test 和其他一些测试文本”
我哪里错了?