加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

针对一个XML,如果不想使用任何第三方控件,只是使用wxString,

发布时间:2020-12-15 23:03:46 所属栏目:百科 来源:网络整理
导读:针对一个XML,如果不想使用任何第三方控件,只是使用wxString,设置属性可以用一下方法来操作 wxString common_tool_wx::set_key_attribute(const wxString file_content_all,const wxString key_parent,const wxString str_find,const wxString str_replace

针对一个XML,如果不想使用任何第三方控件,只是使用wxString,设置属性可以用一下方法来操作

wxString common_tool_wx::set_key_attribute(const wxString& file_content_all,const wxString& key_parent,const wxString& str_find,const wxString& str_replace)
{
	
	bool flag=false;
	wxString file_context    = file_content_all;
	wxString file_context_result ="";
	int len = file_context.length();
	if(len<=0)
	{
		return wxEmptyString;
	}
	
	wxString key_parent_before    = "";
	wxString key_parent_context    = "";
	wxString key_parent_after    = "";
	
	wxString key_parent_begin="";
	wxString key_parent_end="";
	       
	wxString str_key_parent = key_parent;
	key_parent_begin =wxString::Format(wxT("<%s"),str_key_parent);
	key_parent_end =wxString::Format(wxT("</%s>"),str_key_parent);

	int pos_key_parent_begin=0;
	int pos_key_parent_end=0;
	int len_key_parent_begin = key_parent_begin.length();
	int len_key_parent_end = key_parent_end.length();

	pos_key_parent_begin = file_context.Find(key_parent_begin);
	if(wxString::npos != pos_key_parent_begin)
	{
		key_parent_before = file_context.substr(0,pos_key_parent_begin);
	}

	pos_key_parent_end = file_context.Find(key_parent_end);
	int i_end=0;
	if(wxString::npos != pos_key_parent_end)
	{
		key_parent_after = file_context.substr(pos_key_parent_end);
	}

	if((pos_key_parent_begin>=0)&&(pos_key_parent_end>=0)&&(pos_key_parent_end-pos_key_parent_begin>=0))
	{
		key_parent_context = file_context.substr(pos_key_parent_begin,pos_key_parent_end-pos_key_parent_begin);
		// start replace
		int iPos_replace = key_parent_context.Find(str_replace);
		if(wxString::npos == iPos_replace)
		{
		     //如果没有str_replace,那么就替换
			 key_parent_context.Replace(str_find,str_replace);
			// cout<<key_parent_context<<endl;
			return key_parent_before + key_parent_context + key_parent_after;
		}
	}
	return "";
}


测试OK

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读