开发者

Need a better way to valid Computer name using C++ code

I am not try开发者_运维问答ing to set the local hostname. In my app using a edit control need to accept a host name (fully qualified with DNS / without).

We do know we cannot use chars a (\ / ! @ # $ % ^). Is there a better way than programmatically parsing the user input.

Code needs to work in all languages (multi byte char set)

Thanks AnilG


Not that I could think of. The effort to do this yourself is pretty slim, though. See _mbschr and _mbscspn for good examples on how to search for a single character and multiple characters.

There is also a good overview over string functions supported by Visual Studio here.

char string[] = "xyzabc";
int pos;

pos = strcspn( string, "abc" );
printf( "First a, b or c in %s is at character %d\n", string, pos );


You can use the PCRE library to match the string against a regular expression.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜