Search code examples
c#stringtrim

How to trim IP Address to get the first 3 parts of it?


I need to trim a given IP Address to get the first 3 parts of it

Example:

"192.168.1.20" ➨ "192.168.1."
"29.6.60.241" ➨ "29.6.60."


Solution

  • String result = input.Substring(0, input.LastIndexOf("."));