January 5,2006
replacing text function in C++
replacing text function in C++
/* replaces every occurrence of c1 in str with c2 */
void replace( char *str, char c1, char c2 )
{
unsigned int i;
for( i = 0; i < strlen( str ); i++ )
if( str == c1 )
str = c2;
}
/* replaces every occurrence of c1 in str with c2 */
/* replaces every occurrence of c1 in str with c2 */
void replace( char *str, char c1, char c2 )
{
unsigned int i;
for( i = 0; i < strlen( str ); i++ )
if( str == c1 )
str = c2;
}
/* replaces every occurrence of c1 in str with c2 */
As Chris has pointed out this function will only work if str contains the string c1, in which case it will be changed to c2.
I know you want to create and optimise your own functions but I suggest you try something like this example:
#include "string.h"
#include "stdio.h"
char str[] = "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";
int main( void )
{
char *pdest;
int result;
printf( "String to be searched:\n %s\n", string );
printf( " %s\n %s\n\n", fmt1, fmt2 );
pdest = strstr( string, str );
result = (int)(pdest - string + 1);
if ( pdest != NULL )
printf( "%s found at position %d\n", str, result );
else
printf( "%s not found\n", str );
}
Found this example here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strstr.2c_.wcsstr.2c_._mbsstr.asp
I know you want to create and optimise your own functions but I suggest you try something like this example:
#include "string.h"
#include "stdio.h"
char str[] = "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] = " 1 2 3 4 5";
char fmt2[] = "12345678901234567890123456789012345678901234567890";
int main( void )
{
char *pdest;
int result;
printf( "String to be searched:\n %s\n", string );
printf( " %s\n %s\n\n", fmt1, fmt2 );
pdest = strstr( string, str );
result = (int)(pdest - string + 1);
if ( pdest != NULL )
printf( "%s found at position %d\n", str, result );
else
printf( "%s not found\n", str );
}
Found this example here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strstr.2c_.wcsstr.2c_._mbsstr.asp
引用URL
http://cgi.blog.roodo.com/trackback/960386
回應文章 
我的判斷如下,不知是否正確,請參考看看...
_chdriver()
_getdriver
這兩個似乎是 磁碟 Control ,在 WinCE 裡沒所謂的 磁碟...所以應該是沒有相對應的Function....
你看看是否可忽略 或是 他如果用途是在指定某個磁碟底下的檔案看能不能指定一個路徑給他...而 _access() 應該是在偵測檔案 是否存在 和 檔案的讀寫狀態
偵測檔案是否存在你可以試試下面的Code:
CFileStatus status;
CString FileName;
if(CFile::GetStatus((LPCTSTR) FileName, status )){
//檔案存在....
}else
//檔案不存在....
若是有用到 檔案的讀寫狀態 你看看 status 的資料是否有提供....
_chdriver()
_getdriver
這兩個似乎是 磁碟 Control ,在 WinCE 裡沒所謂的 磁碟...所以應該是沒有相對應的Function....
你看看是否可忽略 或是 他如果用途是在指定某個磁碟底下的檔案看能不能指定一個路徑給他...而 _access() 應該是在偵測檔案 是否存在 和 檔案的讀寫狀態
偵測檔案是否存在你可以試試下面的Code:
CFileStatus status;
CString FileName;
if(CFile::GetStatus((LPCTSTR) FileName, status )){
//檔案存在....
}else
//檔案不存在....
若是有用到 檔案的讀寫狀態 你看看 status 的資料是否有提供....
Posted by roger5089
at January 5,2006 17:36
fix char[] = unsigned short *
char A[100];
unsigned short *B;
B=(unsigned short *)(&A[0]);
char A[100];
unsigned short *B;
B=(unsigned short *)(&A[0]);
Posted by roger5089
at January 11,2006 15:51
[URL=http://www.estatico.cn/albergo-all-isola-d-elba] albergo all isola d elba [/URL] albergo all isola d elba [URL=http://www.estatico.cn/cuoco-it] cuoco it [/URL] cuoco it [URL=http://www.estatico.cn/presa] presa [/URL] presa
Posted by Jason
at June 11,2008 09:56