AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   "Replace" command ? (https://forums.alliedmods.net/showthread.php?t=37191)

Cr3V3TT3 01-22-2005 16:03

"Replace" command ?
 
hi
In small i used the "replace" command to replace a string in a string

But I don' t know what is this command in C++

Like
Code:

strcpy(prepare_hud, "Round $rn");
replace(prepare_hud, 127 , "$rn", "3");

i wan' t prepare_hud = "Round 3"

What the true code? :?

Sorry for this noob question ...

vancelorgin 01-22-2005 23:53

It's much easier if you use std::strings :

Code:

void ReplaceTerm(std::string& strDest, const char* lpcTerm, const char* lpcReplace){
        int iTermLen = strlen(lpcTerm);
        int iPos = 0;

        while((iPos = strDest.find(lpcTerm)) != std::string::npos)
                strDest.replace(strDest.begin() + iPos, strDest.begin() + iPos + iTermLen, lpcReplace);
}


Manip 01-23-2005 00:22

Except std strings are evil and shit...

PM 01-23-2005 03:17

Quote:

Originally Posted by Manip
Except std strings are evil and shit...

No, they are excellent.

Cr3V3TT3 01-23-2005 09:29

Thx
Where have you find it plz?
Or have you got an example?

( Because i don' t know what is std lol )

PM 01-23-2005 15:38

Try to google on STL C++ or something ^^

The std::string class is part of the Standard Template Library (STL).

Example:
Code:

#include <string>

void func()
{
  std::string str = "hi";
  str += " there!";
  printf("%s", str.c_str());
}


Cr3V3TT3 01-23-2005 15:44

Quote:

Originally Posted by PM
Try to google on STL C++ or something ^^

I' m so exeting to make my plugin ^^
I forgot THE google lOl

Thx

Bad HAL 9000 01-24-2005 13:38

I dont know If I should say what everyone is thinking or not

Cr3V3TT3 01-24-2005 13:50

Quote:

Originally Posted by Bad HAL 9000
I dont know If I should say what everyone is thinking or not

i' m a noob?
you can tell it lol


All times are GMT -4. The time now is 17:49.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.