• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

在VC中有没有函数或者类可以用来实现VB中的Replace Function,在线急待

firza 2002-05-16 12:30:08
VB中的Replace定义如下:
Replace(expression, find, replace[, start[, count[, compare]]])


...全文
47 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
z_j 2002-05-16
上面合在一起 为 XString.h
回复
z_j 2002-05-16
//==============================================================================
// Funktionen auf Element-Strings
//==============================================================================
public:
static char SEP;
static char OLDSEP;
static char SetSeparator(char c) { OLDSEP = SEP; SEP = c; return SEP; }
static char RestoreSeparator() { SEP = OLDSEP; return SEP; }

XString Elements(int von, int bis = -1) const;
XString Elements(int von, int bis, char sep) const;
XString Element(int i) const { return Elements(i, i); }
XString Element(int i, char sep) const;

XString operator()(int i) const { return Elements(i, i); }
XString operator()(int von, int bis) const { return Elements(von, bis); }

XString GetString(int i) const { return Element(i); }
double GetDouble(int i) const { return Element(i).Double(); }
char GetChar(int i) const { return Element(i).Char(); }
int GetInt(int i) const { return Element(i).Int(); }
bool GetBool(int i) const { return Element(i).Bool(); }

void Get(XString& ret, int i) const { ret = GetString(i); }
void Get(double& ret, int i) const { ret = GetDouble(i); }
void Get(char& ret, int i) const { ret = GetChar(i); }
void Get(int& ret, int i) const { ret = GetInt(i); }
void Get(bool& ret, int i) const { ret = GetBool(i); }

XString GetString(int i, char sep) const { return Element(i, sep); }
double GetDouble(int i, char sep) const { return Element(i, sep).Double(); }
char GetChar(int i, char sep) const { return Element(i, sep).Char(); }
int GetInt(int i, char sep) const { return Element(i, sep).Int(); }
bool GetBool(int i, char sep) const { return Element(i, sep).Bool(); }

XString SetElement(int pos, const XString& rep) const;
XString SetElement(int pos, double rep) const { return SetElement(pos, dtoa(rep)); }
XString SetElement(int pos, char rep) const { return SetElement(pos, XString(rep)); }
XString SetElement(int pos, int rep) const { return SetElement(pos, itoa(rep)); }
XString SetElement(int pos, bool rep) const { return SetElement(pos, itoa((int) rep)); }

int ElementIndex(const XString& such) const;
int ElementIndex(double such) const;
int ElementIndex(int such) const;
int ElementIndex(char such) const;
int ElementIndex(bool such) const;

XString ElementSortString() const;
XString ElementSortChar() const;
XString ElementSortInt() const;
XString ElementSortDouble() const;
XString ElementSort() const { return ElementSortString(); }

XString GetDoubleFormatString() const;

public:
XString& Inc();
friend XString itoa(int i);
friend XString utoa(UINT u);
friend XString dtoa(double d);
friend XString dtoa(double d, int n);
friend XString ltoa(long d);
friend XString ultoa(unsigned long d);


friend XString Repeat(char c, int n);
friend XString Repeat(const XString& str, int n);
friend XString GetDoubleFormatString(const XString& str);
friend XString GetStringTableEntry(UINT id);

friend XString Concat(XS&,XS&);
friend XString Concat(XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
friend XString Concat(XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&,XS&);
};

void AFXAPI SerializeElements(CArchive& ar, XString* pElements, int nCount);

extern XString STRERROR;

#endif // __XSTRING__
回复
z_j 2002-05-16
/*****************************************************************************
*
* Autor: Joachim Raidl
* Adresse: Joachim.Raidl@iname.com
* Klasse: XString
* JRRC: %J%
*
****************************************************************************/

#ifndef __XSTRING__
#define __XSTRING__

class XString;

typedef const XString XS;

class XString : public CString
{
//==============================================================================
// Konstruktoren
//==============================================================================
public:
XString() : CString() {}
XString(const XString& xstr) : CString(xstr) {}
XString(const CString& cstr) : CString(cstr) {}
XString(TCHAR c, int nRepeat = 1) : CString(c, nRepeat) {}
XString(LPCTSTR lptstr, int nLength): CString(lptstr, nLength) {}
XString(const unsigned char* psz ) : CString(psz) {}
XString(LPCSTR lpstr ) : CString(lpstr) {}
XString(const int i) : CString(itoa(i)) {}
XString(const UINT u) : CString(utoa(u)) {}
XString(const double d) : CString(dtoa(d)) {}
XString(LPCWSTR lpwstr ) : CString(lpwstr) {}
XString(const unsigned long d) : CString(ultoa(d)) {}
XString(const long d) : CString(ltoa(d)) {}
//==============================================================================
// Operatoren
//==============================================================================
public:
operator CString () const { return *this; }

XString operator--() { *this = Left(GetLength() - 1); return *this; }
XString operator--(int) { XString copy(*this); *this = Left(GetLength() - 1); return copy; }
int operator!() const { return IsEmpty(); }

//==============================================================================
// Funktionen
//==============================================================================
public:
double Double() const { return atof(m_pchData); }
long Long()const { return (long)atof(m_pchData); }
int Int() const { return atoi(m_pchData); }
char Char() const { return m_pchData[0]; } // Kein Fehler bei Leerstring
bool Bool() const { return (Int() != 0); }

XString Remove(int von=0, int bis=-1) const;
XString Remove(const XString& s) const;
XString Remove(char c) const;

XString RemoveAll(const XString& s) const;
XString RemoveAll(char c) const;

XString Insert(const XString& s, int at=0) const;

XString Replace(const XString& s, int von=0, int bis=-1) const;
XString Replace(const XString& s, const XString& search) const;

int ReplaceAll(const XString& s, const XString& search);

// NC... = NoCase... ==> Gro?/Kleinschreibung wird nicht beachtet
int NCFind(const XString& s) const;
int NCFind(char c) const;

XString NCRemove(const XString& s) const;
XString NCRemove(char c) const;

XString NCRemoveAll(const XString& s) const;
XString NCRemoveAll(char c) const;

XString NCReplace(const XString& s, const XString& search) const;
int NCReplaceAll(const XString& s, const XString& search);

XString Reverse() const { XString copy = *this; copy.MakeReverse(); return copy; }

XString Trim() const { XString copy = *this; copy.TrimRight(); copy.TrimLeft(); return copy; }
XString Lower() const { XString copy = *this; copy.MakeLower(); return copy; }
XString Upper() const { XString copy = *this; copy.MakeUpper(); return copy; }


XString Left(int n) const { return CString::Left(n); }
XString Mid(int i) const { return CString::Mid(i); }
XString Mid(int i, int n) const { return CString::Mid(i, n); }
XString Right(int n) const { return CString::Right(n); }

XString Fill(int n) const;
XString ReplaceTabs(int abstand = 4) const;

int Count(char c) const;
int Count(const XString& str) const;
int FindIndex(char c, int pos) const;
XString ReplaceText(const XString& replace) const;

XString FromTo(int von, int bis) { return Mid(von, bis-von+1); }


回复
firza 2002-05-16
能否举个例子?
回复
Muf 2002-05-16
CString.Replace行吗?

不行的话,请用Regular Expression(正则表达式)。
正则表达式的类,Microsoft有下载。也可以使用Boost的类。(www.boost.org)
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2002-05-16 12:30
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……