Autore Topic: Nuovo comportamento per l'istruzione Split()  (Letto 225 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.334
  • Ne mors quidem nos iunget
    • Mostra profilo
Nuovo comportamento per l'istruzione Split()
« il: 30 Novembre 2014, 01:55:42 »
Vi segnalo questo messaggio di Minisini !!!


" I'm defining a new behaviour for the Split() instruction, that is
normally backward-compatible.


    
Codice: gambas [Seleziona]
Split("abcd",";","\\;")


splits the "abcd" string with the ";" character, and uses the backslash
character for escaping it.

This behaviour is enabled when the escape string (the third argument)
has two characters, and its second character is the same as the first
splitting character (the second argument). Then the first character of
the escape string is the escape character (usually a backslash).

What do you think about that?

--
Benoît Minisini
"


« Ultima modifica: 30 Novembre 2014, 02:01:28 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.334
  • Ne mors quidem nos iunget
    • Mostra profilo
Nuovo comportamento per l'istruzione Split()
« Risposta #1 il: 30 Novembre 2014, 01:57:55 »
 ...continua...


" Before that, Split("abcd",";","\\;") did nothing useful, as an escape
character cannot be a splitting character. No error was raised in that
case, you just got some undefined behaviour.

So I decided to use that syntax to implement a different way of
splitting the string. Instead of escaping with enclosing characters
(everything between these two characters cannot be split), I escape
characters one by one with the special character indicated in the
beginning of the escape string.

Regards,

--
Benoît Minisini
"


" I would like to see an example of before and after as well.

I think I had a need for exactly this the other day. I wanted to split a comma delimited list except where the comma is immediately followed by a space. Will this change help that?

regards
Bruce
"


" No. It's for splitting such string with the ';' character:

"blue;blue\\;yellow;green"

to get:

["blue","blue;yellow","green"]

--
Benoît Minisini
"
« Ultima modifica: 30 Novembre 2014, 02:04:14 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »