swscanf反向格式化字符串为相应的数据

Posted zeqi1991

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swscanf反向格式化字符串为相应的数据相关的知识,希望对你有一定的参考价值。

int main(int argc, const char* argv[])

	if (1)
	
		const TCHAR* dsnContent = _T("wwnl_title$wwnl_title&层号$层号$Floor No$12");
		//const TCHAR* dsnContent = _T("wwnl_title$wwnl_title&层号$层号$Floor No");
		TCHAR k1[1024] =  0 ;
		TCHAR k2[1024] =  0 ;
		TCHAR k3[1024] =  0 ;
		TCHAR k4[1024] =  0 ;
		TCHAR k5[1024] =  0 ;
		int no = 0;
		int nCount = swscanf_s(dsnContent, _T("%[^$]$%[^&]&%[^$]$%[^$]$%[^$]$%d"), k1, 1024, k2, 1024, k3, 1024, k4, 1024, k5, 1024, &no);
		//int nCount = swscanf_s(dsnContent, _T("%[^$]$%[^&]&%[^$]$%[^$]$%[^\\t]"), k1, 1024, k2, 1024, k3, 1024, k4, 1024, k5, 1024, &no);
		if (nCount == 6)
		
			CString prompt;
			prompt.Format(_T("1:%s,2:%s,3:%s,4:%s,5%s"), k1, k2, k3, k4, k5);
			OutputDebugString(prompt);
		
		int i = 0;
	


	const TCHAR* onelineContent = _T("超单元编号[123]:节点编号[11,2,3,4],节点坐标[(1.0,1.0,1.0),(1.0,1.0,1.0),(1.0,1.0,1.0),(1.0,1.0,1.0)]");
	struct Point 
	
		double x;
		double y;
		double z;
	;
	struct SuperPartData 
	
		int nPartNum;
		std::vector<int> nodeIndexVec;
		std::map<int, std::vector<Point>> nodeCoordMap;
	;

	SuperPartData data;
	data.nodeIndexVec.resize(4);
	TCHAR partNoPrompt[128] =  0 ;
	TCHAR nodeNoPrompt[128] =  0 ;
	TCHAR nodeCoordPrompt[128] =  0 ;
	int nPartNum = 0;
	std::vector<int> curNodeNo(4);
	Point pt1, pt2, pt3, pt4;
	int nCount = swscanf(onelineContent, _T("%[^[][%d]:%[^[][%d,%d,%d,%d],%[^[][(%lf,%lf,%lf),(%lf,%lf,%lf),(%lf,%lf,%lf),(%lf,%lf,%lf)]"),
		partNoPrompt, &nPartNum, nodeNoPrompt, &curNodeNo[0], &curNodeNo[1], &curNodeNo[2], &curNodeNo[3], nodeCoordPrompt,
		&pt1.x, &pt1.y, &pt1.z, &pt2.x, &pt2.y, &pt2.z, &pt3.x, &pt3.y, &pt3.z, &pt4.x, &pt4.y, &pt4.z);

	return 0;

以上是关于swscanf反向格式化字符串为相应的数据的主要内容,如果未能解决你的问题,请参考以下文章

sscanf函数

C语言 sscanf用法详解

C++里sscanf()与swscanf()的使用

C++里sscanf()与swscanf()的使用

C++里sscanf()与swscanf()的使用

swscanf_s和sscanf_s的使用