Advertisement
Guest User

Biblioteca de String - Funcoes [iPs]TeaM

a guest
Feb 4th, 2011
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #define iStrLoop(%0,%1)   for (new %1 = 0, j = strlen(%0); %1 < j; ++%1)
  2. #define MaxChars 256
  3.  
  4. stock iStrReverse(sStr[])
  5. {
  6.     new sTmp[MaxChars];
  7.     for(new j = strlen(sStr); j > -1; --j)
  8.     {
  9.         sTmp[strlen(sTmp)] = sStr[j];
  10.     }
  11.     return sTmp;
  12. }
  13.  
  14. stock iStrReplace(sFrom[],sStr[],sTo[])
  15. {
  16.     new iFind = strfind(sFrom,sStr,true);
  17.     strdel(sFrom,iFind,iFind + strlen(sStr));
  18.     strins(sFrom,sTo,iFind,MaxChars);
  19.     return sFrom;
  20. }
  21.  
  22. stock iStringDel(sFrom[],sDel[])
  23. {
  24.     return iStrReplace(sFrom,sDel,"");
  25. }
  26.  
  27. stock iStrNumeric(sStr[])
  28. {
  29.     iStrLoop(sStr,o)   
  30.         if (sStr[o] > '9' || sStr[o] < '0') return false;  
  31.     return true;
  32. }
  33.  
  34. stock iValToStr(iVal)
  35. {
  36.     new sStr[12];
  37.     valstr(sStr,iVal);
  38.     return sStr;
  39. }
  40.  
  41. stock iCharToChar(sStr[],cChar1,cChar2)
  42. {
  43.     iStrLoop(sStr,o) if(sStr[o] == cChar1) sStr[o] = cChar2;
  44.     return sStr;
  45. }
  46.  
  47. stock iStrToStr(sStr[],sTo[],iIni,iEnd)
  48. {
  49.     strmid(sTo,sStr,iIni,iEnd,MaxChars);
  50.     strdel(sStr,iIni,iEnd);
  51.     return sTo;
  52. }
  53.  
  54. stock iStrCopyStr(sStr[],sTo[])
  55. {
  56.     format(sTo,MaxChars,sStr);
  57.     return sTo;
  58. }
  59.  
  60. stock iRamdomStr(iMaxLen)
  61. {
  62.     new
  63.         sStr[128],
  64.         sOut[61] = "qwertyuiop´[asdfghjklç~]zxcvbnm,.;/\'1234567890-=¹³£²³¢£³¢£¢¬";
  65.     for(new i, j = strlen(sOut); i < iMaxLen; ++i)
  66.     {
  67.         sStr[i] = sOut[random(j)];
  68.     }
  69.     return sStr;
  70. }
  71.  
  72. stock iStrLower(sStr[])
  73. {
  74.     iStrLoop(sStr,i) if (0x41 <= sStr[i] <= 0x5A) sStr[i] += 32;
  75.     return sStr;
  76. }
  77.  
  78. stock iStrUpper(sStr[])
  79. {
  80.     iStrLoop(sStr,i) if (0x61 <= sStr[i] <= 0x7A) sStr[i] -= 32;
  81.     return sStr;
  82. }
  83.  
  84. //#define strtok(%1,%0) iStrTok(%1,1)
  85. stock iStrTok(sStr[],iSpace,cSplit = ' ')
  86. {
  87.     new iLoop = 0,iSpaces = 0,iStr[32];
  88.     while(iSpaces != iSpace) if(sStr[++iLoop] == cSplit) ++iSpaces;
  89.     ++iLoop,format(iStr,32,sStr[iLoop]);
  90.     return iStr;
  91. }
  92.  
  93. stock iStrFilter(sStr[])
  94. {
  95.     new  sFilter[56]    = "çÇáéíóúýÁÉÍÓÚÝàèìòùÀÈÌÒÙãõñäëïöüÿÄËÏÖÜÃÕÑâêîôûÂÊÎÔÛ æ¿•";
  96.     new sFiltred[56]    = "cCaeiouyAEIOUYaeiouAEIOUaonaeiouyAEIOUAONaeiouAEIOU o?°";
  97.     iStrLoop(sStr,i)            for(new l; sFilter[l]; ++l)
  98.     if(sStr[i] == sFilter[l])   sStr[i] = sFiltred[l];
  99.     return sStr;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement