# Detect a language from a string in C#.NET

Let's say you have a simple string in any language as your business forces you to let the client enter so you need to detect the language of the respected string at run time. We might have the varity of ways to solve solve this problem , but as a lazy .NET Developer, I am going to introduce a very simple Nuget tool to do job for you in less than a second.

First of all, create a simple Console Application in Visual Studio or in/by any IDE you want. Like below screen. 👇

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665429145/4fa7254d-1256-493e-b1e1-30cd45b7e488.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665426748/3d566e4e-20c1-44be-8ec2-5a1319b01171.jpeg align="center")

then you would have a simple solution like what I have shared below. 👇

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665451579/ad08e791-e751-40b0-ade3-10a1bee68d4b.jpeg align="center")

The next step is adding LanguageDetection.NETStandard Nuget package to the solution.

%[https://www.nuget.org/packages/LanguageDetection.NETStandard/] 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665508048/13567830-67fe-45a6-bd5d-40962e732b25.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665550671/cf6468d2-0f30-47a6-bd6d-a7e375bffe5c.jpeg align="center")

To make the long story short, just go through the simple piece of code that I have written.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665574284/d055ddfc-4ffe-471b-a1c9-511c3e6e4dc4.jpeg align="center")

As you can see, the result is not bad.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665736668/d782551b-edf5-406e-a173-816309924040.jpeg align="center")

but if I try a different language ?. Something like Persian might be a little bit tricky!. Let's see.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1689665757245/32c5d75a-e03f-4768-8eb4-8610ac8eb8a4.jpeg align="center")

Not bad !.

Since you guys are totally lazy to write even 3 lines of code, I do share the code with you below.

```csharp
using LanguageDetection;

var LangDetector = new LanguageDetector();


LangDetector.AddAllLanguages();

//string MySimpleText = "This Text is a simple damn English string. Detect if you can!.";

string MySimpleText = "این یک متن فارسی ساده است. اگر مردی، این را تشخیص بده";


var Result=  LangDetector.Detect(MySimpleText);

Console.WriteLine(Result);

```

That's all.

Enjoy C# development for ever...
