PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → WINDEV functions
WINDEV functions
Débuté par JON LAU, 21 juin 2018 10:29 - 7 réponses
Posté le 21 juin 2018 - 10:29
Hi,

Is there WINDEV function where i can replace a char string within certain position in a text file/buffer ?
Or i can only depend on POSITION(),MIDDLE(), LEFT() etc.. to concatenate ?

Cheers,

JON LAU
Posté le 21 juin 2018 - 10:43
If you know the position and length in advance or with the POSITION / LENGTH function you can use the [[ operator to replace or extract what you need.

https://doc.windev.com/en-US/…
Posté le 21 juin 2018 - 13:00
Hi,

be aware that Paulo answer is correct ONLY if your replacement string is the same length than the replaced one...

Personnaly, I wrote a long time ago a replace function that works with any lenght (it's just a few lines with left, right and concatenation), and I'm using it when needed.

Best regards
Posté le 22 juin 2018 - 06:29
Quote
Fabrice Harari

Hi,





be aware that Paulo answer is correct ONLY if your replacement string is the same length than the replaced one...





Personnaly, I wrote a long time ago a replace function that works with any lenght (it's just a few lines with left, right and concatenation), and I'm using it when needed.





Best regards

Hi Fabrice,

ok, so it seems i need to use left, right to concatenate instead of a single function.

Cheers,

JON LAU
Posté le 22 juin 2018 - 13:39
yes, ONCE, to create your own function.

Best regards
Posté le 22 juin 2018 - 16:56
Hi John,

I don't think the replace string has to have the same length (anymore?)
In WB 22 this works if you give "hello" as a parameter to the function below:
PROCEDURE test(sSubst) sText is string sText="I say xxx there" sText[[7 TO 9]]=sSubst RESULT sText Kind regards,
Piet
Posté le 22 juin 2018 - 20:24
Hi Guys,

Why do you not use replace?

Info(Replace("xxx All how are Yo all doing","xxx","hello",IgnoreCase))
Cheers
Tor-Bjarne
Posté le 23 juin 2018 - 13:49
Hi Tor-Bjarne,

Quote
within certain position
In the case you are describing ALL occurences of xxx will be replaced, which was not the question.
But I saw a new syntax for the replace function, where one can specify position en length of the string to be replaced.
So in this case replace could be the most elegant solution.

Kind regards,
Piet