Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Replace all substring in string
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
function ReplaceStrInSubstrs(inputString,phr,newstr) local str = inputString local r = "" local roll = true if string.find(str,phr) then while roll do local a = string.find(str,phr) local b = a + #phr for i = 1,#str do if i >= a and i < b then r = r..newstr else r = r..str:sub(i,i) end end str = r r = "" if not string.find(str,phr) then roll = false end end end return str end print (ReplaceStrInSubstrs("Hello &World& Fuck &the& day","&","%"))
[
+
]
Show input
Absolute running time: 0.12 sec, cpu time: 0.07 sec, memory peak: 3 Mb, absolute service time: 0,13 sec
edit mode
|
history
|
discussion
Hello %World% Fuck %the% day