c# Mobile phone number masking

Viewed 50

I want to mask the middle of the phone number

Since a phone number can have 3 to 12 digits, I think you need to calculate the number of digits and process it.

In java procedure, it is handled like this

WHEN LENGTH(phoneNmmber) < 3 THEN phoneNmmber  
WHEN LENGTH(phoneNmmber) < 7 THEN RPAD(SUBSTR(phoneNmmber,1,3), LENGTH(phoneNmmber), '*')  
ELSE CONCAT(LEFT(phoneNmmber, 3), RPAD('', LENGTH(phoneNmmber) - 7, '*'), RIGHT(phoneNmmber, 4))

I want to convert it in a different way. I want to convert a query written in mysql to an mssql query. Can you do the same?

1 Answers

This is not a 'java procedure' and definitely not Java code. This is an SQL statement. If you are using the same database with your C# program, you should be able to use the same code. Otherwise, use these hints to convert your SQL code to C# code:

WHEN THEN statement --> if () else () ....
LENGTH --> String.Length
RPAD --> String.PadRight()
CONCAT --> String.Concat()
SUBSTRING --> String.Substring()
LEFT --> String.Substring()
RIGHT --> String.Substring(String.Length - X)
Related