Click here to Skip to main content
15,798,592 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So I'm trying to make a program that applies sound changes to input text. Anyways, in this specific part, I want the program to find every time "f" is preceded by certain vowels and then replace that "f" with "b". I had it working for some words ("ep" - which is made "ef" earlier in the program - for example does become "eb" as expected). When given "epa", though, the program returns "ef" rather than "eb" (loss of the "a" is expected). Right now, it won't even return anything, giving me the error "Argument 'Start' must be greater than zero." And that error doesn't go away when I think I've made it quite higher than 0 (By changing the initial value of Searcher)...

VB
Dim Searcher As Integer
For Searcher = 1 To (Input.Length - 1)
     If ((Mid$(Input, Searcher - 1, 1) = "o") Or (Mid$(Input, Searcher - 1, 1) = "ō")
     Or (Mid$(Input, Searcher - 1, 1) = "e") Or (Mid$(Input, Searcher - 1, 1) = "ē")
     Or (Mid$(Input, Searcher - 1, 1) = "a") Or (Mid$(Input, Searcher - 1, 1) = "ā")) Then
          If Mid$(Input, Searcher, 1) = "f" Then
               Input = Input.Remove(Searcher, 1)
               Input = Input.Insert(Searcher, "b")
          End If
     End If
Next
Posted

1 solution

Use Regular Expressions(namespace System.Text.RegularExpressions):

Add the following Import:
VB
Imports System.Text.RegularExpressions


Then use the following code:
VB
Dim pattern As String = "[aeo]+[f]+"
Dim input As String = "thought thing though thefm through thus thorough this hellof apqaf efsdsds"
Dim replacement As String = "b"
Dim rgx As New Regex(pattern)
Dim result As String = rgx.Replace(input, replacement)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900