wxWidgetファイルパス処理および文字列分割
久しぶりに文章を出して、福祉を出してコードを入れましょう.くだらないことは言わないで、直接コードをつけます.
ヘッダファイル:
ヘッダファイル:
#ifndef WXWIDGETHELPER_H
#define WXWIDGETHELPER_H
#pragma once
#include
#include
/**
* @brief .
* @param sFilePath .
* @retrive wxString .
* @remarks
Use like this:
* @code
wxString s = GetFilePath("temp\\DEM.tif");
// :"temp
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 4th Feb,2015.
*/
wxString GetFilePath(wxString sFilePath);
/**
* @brief , .
* @param sFilePath .
* @retrive wxString .
* @remarks
Use like this:
* @code
wxString s = GetFileName("temp\\DEM.tif");
// :DEM
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 4th Feb,2015.
*/
wxString GetFileName(wxString sFilePath);
/**
* @brief .
* @param sFilePath .
* @retrive wxString .
* @remarks
Use like this:
* @code
wxString s = GetFullName("temp\\DEM.tif");
// :DEM.tif
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 4th Feb,2015.
*/
wxString GetFullName(wxString sFilePath);
/**
* @brief , .
* @param sFilePath .
* @param sAppendName .
* @retrive wxString .
* @remarks
Use like this:
* @code
wxString s = GetNewFullPath("temp\\DEM.tif","Avg.tif");
// :temp\\Avg.tif
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 4th Feb,2015.
*/
wxString GetNewFullPath(wxString sFilePath,wxString sNewFileName);
/**
* @brief , .
* @param sFilePath .
* @param sAppendName .
* @retrive wxString .
* @remarks
Use like this:
* @code
wxString s = GetNewFullPath2("temp\\DEM.tif","_Avg.tif");
// :temp\\DEM_Avg.tif
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 4th Feb,2015.
*/
wxString GetNewFullPath2(wxString sFilePath,wxString sAppendName);
/**
* @brief .
* @param pString [in] .
* @param cSpliter [in] .
* @remarks
Use like this:
* @code
wxArrayString arry = wxSplitString("a,b,c,d",',');
size_t count = arry.GetCount();
wxPrintf(_T("\arrysize = %u
"), count);
for ( size_t arg = 0; arg < count; arg++ )
{
wxPrintf(_T("\tarry[%u] = %s
"), arg, arry[arg].c_str());
}
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 25th Mar,2015.
*/
wxArrayString wxSplitString(const wxChar *pString,const wxChar cSpliter);
/**
* @brief .
* @param pString [in] .
* @param pSpliter [in] .
* @remarks
Use like this:
* @code
wxArrayString arry = wxSplitString(",,a,b,,,c,,,d,adsdsd,sdfwee,dddd,",",");
size_t count = arry.GetCount();
wxPrintf(_T("\arrysize = %u
"), count);
for ( size_t arg = 0; arg < count; arg++ )
{
wxPrintf(_T("\tarry[%u] = %s
"), arg, arry[arg].c_str());
}
* @endcode
* @author Zhengwen.Fu
* @history - 1.Created by Zhengwen.Fu on 25th Mar,2015.
*/
wxArrayString wxSplitString(const wxChar *pString,const wxChar *pSpliter);
#endif
ソースファイル:#include "wxWidgetHelper.h"
wxString GetFilePath(wxString sFilePath)
{
wxFileName fName(sFilePath);
return fName.GetPath();
}
wxString GetFileName(wxString sFilePath)
{
wxFileName fName(sFilePath);
return fName.GetName();
}
wxString GetFullName(wxString sFilePath)
{
wxFileName fName(sFilePath);
return fName.GetFullName();
}
wxString GetNewFullPath(wxString sFilePath,wxString sNewFileName)
{
wxFileName fName(sFilePath);
return (fName.GetPath()+"\\"+sNewFileName);
}
wxString GetNewFullPath2(wxString sFilePath,wxString sAppendName)
{
wxFileName fName(sFilePath);
return (fName.GetPath()+"\\"+fName.GetName()+sAppendName);
}
wxArrayString wxSplitString(const wxChar *p,const wxChar cSpliter)
{
wxArrayString arry;
wxString str;
str.reserve(1024);
while (true)
{
while(*p==cSpliter)
p++;
if(*p == _T('\0'))
break;
for (str.Clear();;p++)
{
if(*p==cSpliter || *p == _T('\0'))
break;
str += *p;
}
arry.push_back(str);
}
return arry;
}
wxArrayString wxSplitString(const wxChar *pString,const wxChar *pSpliter)
{
wxArrayString arry;
wxString s(pString);
while (true)
{
int pos = s.Find(pSpliter);
if (pos == 0)
{
s = s.substr(1);
continue;
}
if(pos == wxString::npos )
{
if(s.Length() > 0)
arry.push_back(s.Trim());
break;
}
arry.push_back(s.substr(0,pos));
s = s.substr(pos+1);
}
return arry;
}
OKです.具体的な使い方はコメントにあります.