# How To Implement Replace Function Without Using The Inbuilt String Function

### Share and Enjoy !

A question was asked to me by one of the reputed firms that can you replace a few characters by another set of characters without using the inbuilt string function…..

Oh… this was a very popular topic during the last few days …finally I found the solution…
I am sharing this function below written…

It is changing HYD with CYB…

``Sub Macro1()Dim bText() As ByteDim j As Integerj = 0Dim k As Integerk = 0Dim finalq As Stringfinalq = ""'Assign the sting with null valuesinputq = InputBox("Enter your string")tttt = Len(inputq) + 3ReDim a(tttt)Dim MyString As String: MyString = inputq'Check the string one by one..character by characterbText = MyStringFor i = 0 To UBound(bText) - 1If (bText(i) = 0) ThenElsea(j) = Chr(bText(i))j = j + 1End IfNextDoIf a(k) = "" ThenElse'Checking Upper case and Lower caseIf ((a(k) = "H" Or a(k) = "h") And (a(k + 1) = "Y" Or a(k + 1) = "y") And (a(k + 2) = "D" Or a(k + 2) = "d")) ThenIf a(k) = "H" Thena(k) = "C"Elsea(k) = "c"End IfIf (a(k + 1) = "Y") Thena(k + 1) = "Y"Elsea(k + 1) = "y"End IfIf (a(k + 2) = "D") Thena(k + 2) = "B"Elsea(k + 2) = "b"End Iffinalq = finalq & a(k) & a(k + 1) & a(k + 2)k = k + 2Elsefinalq = finalq & a(k)End IfEnd Ifk = k + 1Loop Until (k = UBound(a))MsgBox finalqinputx = InputBox("Want to do again")If inputx = "Y" ThenCall Macro1ElseEnd IfEnd Sub``

We are done. This can be more dynamic by using replacing character is taken from the user.

### 2 thoughts on “How To Implement Replace Function Without Using The Inbuilt String Function”

1. hello,
the program actually runs very well but it actually wastes 2 bytes space. Inplace u can write as:
For i = 0 To UBound(bText) – 3

2. Animesh Chatterjee

Hi,
Thank you very much for the upgraded solution …Yes, i agree that the array deceleration is not up to the mark. It was a quick solution given.
I will write a fresh code without the waste of space.

Thanks for the review and happy reading.