Post Reply 
String Library
11-16-2015, 12:11 PM
Post: #1
String Library
Bonjour
Je vous propose une petite bibliothéque de fonctions traitant des chaînes de caractères.
Un fichier tetxe vous en détaille le contenu.
Espérant que cela vous sera utile.
Merci de vôtre attention.

Hello
I propose a small library of functions dealing with strings.
A Tetxe you file details the content .
Hoping that it will help.
Thanks for your attention.


Attached File(s)
.zip  Strlib.zip (Size: 4.47 KB / Downloads: 50)

Sorry for my english
Find all posts by this user
Quote this message in a reply
12-07-2015, 09:43 PM
Post: #2
RE: String Library
Bonjour
Je vous propose une nouvelle fonction à ajouter à la library:

Hello
I propose a new function to add to the library :

Code:
EXPORT EXTRACT(s,o)
//string,char or {char,num}
BEGIN
 LOCAL n:=-1,p,c;
 IF TYPE(o)==6 THEN
  c:=o(1);n:=o(2);
 ELSE
  c:=o;
 END;
 c:=typara(c);p:=INSTRING(s,c);
 n:=IFTE(n<0,DIM(s)-p+1,n);
 IF p==0 OR n==0 THEN
  "";
 ELSE
  MID(s,p,n);
 END;
END;
exemple:
example:
EXTRACT("250_km","_") -> "_km"
EXTRACT("250_km de bouchons",{"_",3}) -> "_km"

Sorry for my english
Find all posts by this user
Quote this message in a reply
12-23-2015, 06:39 AM (This post was last modified: 12-23-2015 06:41 AM by Tyann.)
Post: #3
RE: String Library
Bonjour
Les fonctions LFORMAT ET RFORMAT ne fonctionnent pas correctement.
Exemple :
LFORMAT(16,2,"0") renvoie "0016" au lieu de "16".
Ceci est du à un bug de la fonction MAKELIST.
Voici une version corrigée de setstr qui est utilisée par ces deux fonctions:

Hello
The LFORMAT AND RFORMAT functions do not work properly.
Example :
LFORMAT (16,2,"0" ) returns " 0016 " instead of "16" .
This is due to a bug in the MAKELIST function.
Here is a corrected version of setstr that is used by these two functions:

Code:

setstr(c,n)
BEGIN
 LOCAL i,r;
 c:=typara(c);r:="";
 FOR i FROM 1 TO n
  r:=r+c;
 END;
 r;
END;
Sorry

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-20-2017, 03:30 PM
Post: #4
RE: String Library
Another function: replace a placeholder in a string with another
e.g. SREPL("Hello %w", "%w", "world") -> "Hello world"

Code:
EXPORT SREPL(str, key, val)
BEGIN
  LOCAL p;
  p := INSTRING(str, key);
  CASE
    IF p == 0 THEN  // Not found
      RETURN str;
    END;
    IF str == key THEN  // Placeholder is whole string
      RETURN val;
    END;
    IF p == 1 THEN  // Placeholder at start
      RETURN val + MID(str, DIM(key)+1);
    END;
    IF p == (DIM(str)-DIM(key)+1) THEN  // Placeholder at end
      RETURN LEFT(str, p-1) + val;
    END;
    DEFAULT RETURN LEFT(str, p-1) + val + MID(str, p+DIM(key));
  END;
END;
Find all posts by this user
Quote this message in a reply
03-20-2017, 08:39 PM
Post: #5
RE: String Library
Bonjour

Sauf erreur, la fonction intégrée REPLACE permet cela.
Merci de vôtre intêret.

Hello

Unless you make a mistake, the built-in REPLACE function allows this.
Thanks for your interest.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-20-2017, 10:18 PM
Post: #6
RE: String Library
(03-20-2017 08:39 PM)Tyann Wrote:  Bonjour

Sauf erreur, la fonction intégrée REPLACE permet cela.
Merci de vôtre intêret.

Hello

Unless you make a mistake, the built-in REPLACE function allows this.
Thanks for your interest.

From the User Guide:

REPLACE("123456", 2, "GRM") -> "1GRM56"

but

SREPL("123456", "2", "GRM") -> "1GRM3456"
Find all posts by this user
Quote this message in a reply
03-20-2017, 10:44 PM (This post was last modified: 03-20-2017 10:48 PM by Tyann.)
Post: #7
RE: String Library
Quote:
Code:
REPLACE("123456", 2, "GRM") -> "1GRM56"

but

Code:
REPLACE("123456", "2", "GRM") -> "1GRM3456"

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-21-2017, 04:36 PM (This post was last modified: 03-21-2017 04:38 PM by BruceH.)
Post: #8
RE: String Library
(03-20-2017 10:44 PM)Tyann Wrote:  
Quote:
Code:
REPLACE("123456", 2, "GRM") -> "1GRM56"

but

Code:
REPLACE("123456", "2", "GRM") -> "1GRM3456"

Ah, I see now what you are saying. You're right.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)