MFC读取一行内容里有"|"符号分离,怎么显示到2个编辑框啊,求大神指教。。。

Esc_TopScholar 2015-01-12 05:04:48
我已读取文件的一行内容,并显示在编辑框中,内容里有“|”符号将一行内容分为几个不同的语言内容:
如---->
我是菜鸟,求大神指教 | I was a rookie, and great advice | 내가 니들한테 어리바리. 제발 바랍니다 | 私は初心者で、求大神お願いします

这一行是像这种格式的一些话,我不知道怎么来判断“|”来把每种语言的内容分别显示在多个编辑框里!!!!
希望知道的朋友指导指导。。。。。。。。。。。
非常感谢!!!!

...全文
184 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-01-14
  • 打赏
  • 举报
回复
引用 6 楼 Esc_TopScholar 的回复:
我是想知道在mfc里的。。。。
你认为我5楼代码中的关键语句不能在mfc里用?
encoderlee 2015-01-14
  • 打赏
  • 举报
回复
两行之间还有个看不见的换行符'\n',根据这个再处理一下
Esc_TopScholar 2015-01-14
  • 打赏
  • 举报
回复
可是我用别的方法做出来了 不过出现新问题了 最后一个“|”读取后它后面的没“|”那个符号,只有下一行才有,如果是2行: 我是菜鸟,求大神指教 | I was a rookie, and great advice | 내가 니들한테 어리바리. 제발 바랍니다 我是菜鸟,求大神指教 | I was a rookie, and great advice | 내가 니들한테 어리바리. 제발 바랍니다 读取出来就变成 我是菜鸟,求大神指教 I was a rookie, and great advice 내가 니들한테 어리바리. 제발 바랍니다 我是菜鸟,求大神指教 //此处就连一起了,应为韩语最后没有“|” I was a rookie, and great advice 怎么弄哟?
赵4老师 2015-01-13
  • 打赏
  • 举报
回复
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
wchar_t s[]=L"我是菜鸟,求大神指教 | I was a rookie, and great advice | 내가 니들한테 어리바리. 제발 바랍니다 | 私は初心者で、求大神お願いします";
wchar_t seps[]=L"|";
wchar_t *token1=NULL;
wchar_t *next_token1 = NULL;
int wmain() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;
	int x,y;

    system("color F0");
	system("cls");
	x=8;
	y=8;
	hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "宋体");
    SelectObject(hdc,hfont);


	token1 = wcstok_s( s, seps, &next_token1);
    while (1) {
        if (token1 != NULL) {
		    TextOutW(hdc,x,y,token1,wcslen(token1));
			y+=20;
            token1 = wcstok_s( NULL, seps, &next_token1);
        } else break;
    }

    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getchar();
    system("color 07");
    system("cls");

	return 0;
}
Esc_TopScholar 2015-01-13
  • 打赏
  • 举报
回复
引用 3 楼 likfeng 的回复:
用CString Find 查找 | ,标记位置, 取字符串...
朋友能具体说个例子?我不是取“|”。我 是要显示“|”之前和之后的数据。。。
Esc_TopScholar 2015-01-13
  • 打赏
  • 举报
回复
我是想知道在mfc里的。。。。
likfeng 2015-01-12
  • 打赏
  • 举报
回复
用CString Find 查找 | ,标记位置, 取字符串...
Esc_TopScholar 2015-01-12
  • 打赏
  • 举报
回复
[quote=引用 1 楼 zhao4zhong1 的回复:] 大神我是菜鸟,别介意我看不懂哟,能举个简单的小列子?
赵4老师 2015-01-12
  • 打赏
  • 举报
回复
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vccrt/html/7696c972-f83b-4617-8c82-95973e9fdb46.htm Run-Time Library Reference strtok_s, _strtok_s_l, wcstok_s, _wcstok_s_l, _mbstok_s, _mbstok_s_l Example See Also Send Feedback Find the next token in a string, using the current locale or a locale passed in. These are versions of strtok, _strtok_l, wcstok, _wcstok_l, _mbstok, _mbstok_l with security enhancements as described in Security Enhancements in the CRT. char *strtok_s( char *strToken, const char *strDelimit, char **context ); char *_strtok_s_l( char *strToken, const char *strDelimit, char **context, _locale_t locale ); wchar_t *wcstok_s( wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context ); wchar_t *_wcstok_s_l( wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context, _locale_t locale ); unsigned char *_mbstok_s( unsigned char*strToken, const unsigned char *strDelimit, char **context ); unsigned char *_mbstok_s( unsigned char*strToken, const unsigned char *strDelimit, char **context, _locale_t locale ); Parameters strToken String containing token or tokens. strDelimit Set of delimiter characters. context Used to store position information between calls to strtok_s locale Locale to use. Return Value Returns a pointer to the next token found in strToken. They return NULL when no more tokens are found. Each call modifies strToken by substituting a NULL character for each delimiter that is encountered. strToken strDelimit context Return value errno NULL any pointer to a null pointer NULL EINVAL any NULL any NULL EINVAL any any NULL NULL EINVAL If strToken is NULL but context is a pointer to a valid context pointer, there is no error. Remarks The strtok_s function finds the next token in strToken. The set of characters in strDelimit specifies possible delimiters of the token to be found in strToken on the current call. wcstok_s and _mbstok_sare wide-character and multibyte-character versions of strtok_s. The arguments and return values of wcstok_s and _wcstok_s_l are wide-character strings; those of _mbstok_s and _mbstok_s_l are multibyte-character strings. These three functions behave identically otherwise. This function validates its parameters. If an error condition occurs, as in the Error Conditions table, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions set errno to EINVAL and return NULL. TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined _tcstok_s strtok_s _mbstok_s wcstok_s _tcstok_s_l _strtok_s_l _mbstok_s_l _wcstok_s_l On the first call to strtok_s the function skips leading delimiters and returns a pointer to the first token in strToken, terminating the token with a null character. More tokens can be broken out of the remainder of strToken by a series of calls to strtok_s. Each call to strtok_s modifies strToken by inserting a null character after the token returned by that call. The context pointer keeps track of which string is being read and where in the string the next token is to be read. To read the next token from strToken, call strtok_s with a NULL value for the strToken argument, and pass the same context parameter. The NULL strToken argument causes strtok_s to search for the next token in the modified strToken. The strDelimit argument can take any value from one call to the next so that the set of delimiters may vary. Since the context parameter supersedes the static buffers used in strtok and _strtok_l, it is possible to parse two strings simultaneously in the same thread. The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. The versions of these functions without the _l suffix use the current locale for this locale-dependent behavior; the versions with the _l suffix are identical except that they use the locale parameter passed in instead. For more information, see Locale. Requirements Routine Required header strtok_s <string.h> _strtok_s_l <string.h> wcstok_s, _wcstok_s_l <string.h> or <wchar.h> _mbstok_s, _mbstok_s_l <mbstring.h> For additional compatibility information, see Compatibility in the Introduction. Example Copy Code // crt_strtok_s.c // In this program, a loop uses strtok_s // to print all the tokens (separated by commas // or blanks) in two strings at the same time. // #include <string.h> #include <stdio.h> char string1[] = "A string\tof ,,tokens\nand some more tokens"; char string2[] = "Another string\n\tparsed at the same time."; char seps[] = " ,\t\n"; char *token1 = NULL; char *token2 = NULL; char *next_token1 = NULL; char *next_token2 = NULL; int main( void ) { printf( "Tokens:\n" ); // Establish string and get the first token: token1 = strtok_s( string1, seps, &next_token1); token2 = strtok_s ( string2, seps, &next_token2); // While there are tokens in "string1" or "string2" while ((token1 != NULL) || (token2 != NULL)) { // Get next token: if (token1 != NULL) { printf( " %s\n", token1 ); token1 = strtok_s( NULL, seps, &next_token1); } if (token2 != NULL) { printf(" %s\n", token2 ); token2 = strtok_s (NULL, seps, &next_token2); } } } Copy Code Tokens: A Another string string of parsed tokens at and the some same more time. tokens .NET Framework Equivalent Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. See Also Concepts String Manipulation (CRT) Locale Interpretation of Multibyte-Character Sequences strcspn, wcscspn, _mbscspn, _mbscspn_l strspn, wcsspn, _mbsspn, _mbsspn_l Send feedback on this topic to Microsoft.

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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