The constant is that always the last 8 numbers are the numbers of the
phone, I wanted to know how I separate these last 8 numbers from the
remaining.
Use Substring
using as parameter the size of your variable minus the number of characters you want to capture.
Remember before checking that the size of string
contains the desired number of characters.
public class Program
{
public static void Main()
{
var telefone = "123 12345678";
Console.WriteLine(telefone);
if(telefone.Length > 8)
Console.WriteLine(telefone.Substring(telefone.Length -8)); //12345678
}
}
FIDDLE net code
link
number="+55 34 98989898"
Turn n1="+55 34"; n2="98989898";
If your variable always contains this format, you can use the Split
method using space as a parameter:
public static void Main()
{
var telefone = "+55 81 12345678";
Console.WriteLine(telefone);
var telefoneSeparado = telefone.Split(' ');
Console.WriteLine("CD País: " + telefoneSeparado[0]); //+55
Console.WriteLine("DDD: " + telefoneSeparado[1]); //81
Console.WriteLine("Número: " + telefoneSeparado[2]); //12345678
}
FIDDLE .net code: link
If your variable does not have a specific format, you can use the String.Remove
method that works similarly to String.Substring
public static void Main()
{
var telefone = "+55 81 12345678";
Console.WriteLine(telefone); //+55 81 12345678
Console.WriteLine(telefone.Substring(telefone.Length -8)); //2345678
Console.WriteLine(telefone.Remove(telefone.Length - 8)); //+55 81
}
Code working in .NET Fiddle link