Useful String Function Contributions

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
Just a random thread where I can post some functions useful for string manipulation:
Code:
[NO-PARSE]/* description: circular rotation of string [src] by [n] count.
 * returns: [src]
----------------------------------------------------------------- */
char *rotstr_l(char *src, int n)
{
  int i, ch;
  for (i = 0; i < n; ++i)
  {
    ch = *src;
    memmove(src, src + 1, strlen(src));
    src[strlen(src)] = ch;
  }
  return src;
}

/* description: circular rotation of string [src] by [n] count.
 * returns: [src]
----------------------------------------------------------------- */
char *rotstr_r(char *src, int n)
{
  int i, ch;
  for (i = 0; i < n; ++i)
  {
    ch = src[strlen(src) - 1];
    memmove(src + 1, src, strlen(src) - 1);
    *src = ch;
  }
  return src;
}
[/NO-PARSE]

Others may post their snippets and functions here as well if they desire :)
 
Last edited:

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top