I need to match the content on web.

For example consider I have one sample code,if i submit that code it should search on web and display the website url where that code exists. I need the code in asp.net and c#.

anyone if knows how to do this Plz do reply

Dani AI

Generated

Short summary and a usable approach in C# that fits an ASP.NET page. was right to point toward a web-search provider; correctly pointed out where to find provider SDKs. Below is a practical workflow (normalize -> shard -> query -> score) plus minimal C# helpers you can adapt.

Normalize and create overlapping token "shingles" so small formatting changes do not break matches:

string NormalizeSource(string src)
{
    src = Regex.Replace(src, @"//.*?$|/\*.*?\*/", "", RegexOptions.Singleline | RegexOptions.Multiline);
    src = Regex.Replace(src, @"\s+", " ").Trim();
    return src;
}

IEnumerable<string> Shingles(string code, int k = 8)
{
    var tokens = Regex.Split(code, @"\W+").Where(t => t.Length > 0).ToArray();
    for (int i = 0; i + k <= tokens.Length; i++)
        yield return string.Join(" ", tokens.Skip(i).Take(k));
}

For each shard, perform a quoted search via whatever web-search or code-hosting API you choose, collect candidate URLs, then score by fragment hits and token-set similarity. Example HTTP call (provider-specific header and query parameters vary):

async Task<IEnumerable<string>> SearchFragmentAsync(string fragment, string apiKey, string endpoint)
{
    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Add("X-API-Key", apiKey); // change as provider requires
        var url = $"{endpoint}?q={Uri.EscapeDataString("\"" + fragment + "\"")}";
        var json = await client.GetStringAsync(url);
        dynamic doc = JsonConvert.DeserializeObject(json);
        return doc.webPages?.value?.Select(v => (string)v.url) ?? Enumerable.Empty<string>();
    }
}

double Jaccard(ISet<string> a, ISet<string> b)
{
    var inter = a.Intersect(b).Count();
    var uni = a.Union(b).Count();
    return uni == 0 ? 0 : (double)inter / uni;
}

Notes and cautions: respect provider rate limits and terms, don’t expect 100% coverage (private repos and non-indexed pages won’t show), and quoted-fragment searches can miss heavily reformatted code. For scale or fuzzier matches, consider MinHash/LSH or targeted code-hosting APIs (for example, repository search endpoints). The snippets above are intentionally generic so they can be wired to any search provider from an ASP.NET/C# app.

Recommended Answers

All 3 Replies

>I have one sample code.

I guess, it is a text.

>if i submit that code it should search on web and display the website url where that code exists.

Use Bing or Google API.

Where can i download google or bing api.

you can get the google api from Google, and the Bing API from Microsoft.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.