[Solved] Replace the same line if contains any word in it in c# [closed]


This is a fairly simple task:

string url = @"http://google.com/adi/727412;sz=728x90;ord=$RANDOM?";

if (url.Contains(@"/adi/"))
{
    int pos = url.IndexOf(";ord"); //// Find first occurence of Ord parameter
    url = url.Insert(pos, ";click=$CLICK"); //// Insert text at position
}

Edit: To accomplish the task for multiple occurences I used a solution from this thread.

{
    string url = "<google.com/adi/727412;sz=728x90;ord=$RANDOM?>; <google.com/adi/727412;sz=300x250;ord=$RANDOM?>";
    string searchString = @"/adi/";

    int n = 0;

    while ((n = url.IndexOf(searchString, n)) != -1)
    {
        n += searchString.Length;
        int pos = url.IndexOf('?', n);
        url = url.Insert(pos, ";click=$CLICK");
    }
}

2

solved Replace the same line if contains any word in it in c# [closed]