Can use regex
, as follows:
C#
string original = @"aaaaaaaaaa""aaaa""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""aaaaaaaaaa""aaaaaaaaaaaaa";
// percorre todas os valores que estejam entre aspas duplas
foreach (Match match in Regex.Matches(original, @"\""+[A-z].*?\""", RegexOptions.IgnoreCase))
{
// pega o valor encontrado e remove as aspas
string valorEncontrado = match.Value.Replace("\"", String.Empty);
// cria uma nova string do tamanho do valor encontrado
string novoValor = new String('b', valorEncontrado.Length);
// substitui o valor original pela nova string, re-adicionando as aspas
original = original.Replace(match.Value, "\"" + novoValor + "\"");
}
VB
Dim original As String = "aaaaaaaaaa""aaaa""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""aaaaaaaaaa""aaaaaaaaaaaaa"
For Each match As Match In Regex.Matches(original, """[A-z].*?""", RegexOptions.IgnoreCase)
Dim valorEncontrado As String = match.Value.Replace("""", String.Empty)
Dim novoValor As String = New String("b"c, valorEncontrado.Length)
original = original.Replace(match.Value, """" + novoValor + """")
Next
See working here in C# and here in VB.
The your code is returning
"bbbbbbbbbb""bbb"aaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaa"bbbbbbbbbb"aaaaaaaaaaaaa
– Marcus Vinicius
if (i==1 || i%3==0 && i != 0)
– Jaedson Barbosa
changes the if statement, leaves it so
– Jaedson Barbosa
I also recommend avoiding the regex as much as possible, because it is very complicated.
– Jaedson Barbosa