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 Byte
Dim j As Integer
j = 0
Dim k As Integer
k = 0

Dim finalq As String
finalq = ""
'Assign the sting with null values
inputq = InputBox("Enter your string")
tttt = Len(inputq) + 3
ReDim a(tttt)
Dim MyString As String: MyString = inputq
'Check the string one by one..character by character
bText = MyString
For i = 0 To UBound(bText) - 1
If (bText(i) = 0) Then
a(j) = Chr(bText(i))
j = j + 1
End If
If a(k) = "" Then
'Checking Upper case and Lower case
If ((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")) Then
If a(k) = "H" Then
a(k) = "C"
a(k) = "c"
End If
If (a(k + 1) = "Y") Then
a(k + 1) = "Y"
a(k + 1) = "y"
End If
If (a(k + 2) = "D") Then
a(k + 2) = "B"
a(k + 2) = "b"
End If
finalq = finalq & a(k) & a(k + 1) & a(k + 2)
k = k + 2
finalq = finalq & a(k)
End If
End If
k = k + 1
Loop Until (k = UBound(a))
MsgBox finalq
inputx = InputBox("Want to do again")
If inputx = "Y" Then
Call Macro1
End If
End Sub

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

See also  How To Solve Synchronization Failures In Selenium or QTP?

Share and Enjoy !

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. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *