Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to replace all ‘0’ int a number with specific digit in C#

1 Answer

0 votes
using System;

class Program
{
    static int convert_0_To_n__(int number, int d) {   
        if (number == 0)  
            return 0;  

        int digit = number % 10;  
        if (digit == 0)  
            digit = d;  

        return convert_0_To_n__(number / 10, d) * 10 + digit;  
    }  
    static int convert_0_To_n(int number, int d) {  
        if (number == 0)  
            return d;  
        else
            return convert_0_To_n__(number, d);  
    }  
    static void Main()
    {
        int number = 1080030; 

        Console.Write(convert_0_To_n(number, 7));
    }
}



/*
run:

1787737

*/

 



answered Apr 20, 2019 by avibootz

Related questions

1 answer 155 views
1 answer 161 views
1 answer 185 views
1 answer 129 views
1 answer 148 views
...