SubName: substitute (chain AsString, search AsString, replaced AsString)
Description:
This is meant to replace a sequence of characters by another within a string.
It uses a syntax close to VB6 REPLACE()
- Chain is the string where characters will be searched for
- search is the string to look for
- Replaced is the string that will replace search
This sub supports the chr(0) character which string.Replace does not.
Dependencies: This sub uses core commands, and does not require any additional library.
Tags: string.replace Replace() strings
Description:
This is meant to replace a sequence of characters by another within a string.
It uses a syntax close to VB6 REPLACE()
- Chain is the string where characters will be searched for
- search is the string to look for
- Replaced is the string that will replace search
This sub supports the chr(0) character which string.Replace does not.
B4X:
Sub substitute(chain As String, search As String, replaced As String)
If chain.IndexOf(search) = 0 Then Return chain
Dim gauche, droite As String
Do While chain.IndexOf(search)>0
chain = chain.substring2(0,chain.IndexOf(search)) & replaced & _
chain.SubString(chain.IndexOf(search)+search.Length)
Loop
Return chain
End Sub
Dependencies: This sub uses core commands, and does not require any additional library.
Tags: string.replace Replace() strings
Last edited: