Android Question PadNZeros

Discussion in 'Android Questions' started by Carlo2015, May 14, 2015.

  1. Carlo2015

    Carlo2015 Member Licensed User

    PHP:
    function PadNZeros($digit$padnum)
    {
        return 
    sprintf("%0".$padnum."d"$digit);


    Can someone please help me with this in b4a?

    Also do we have an equivalent function for ucfirst (uppercase first character in php)?

    Thanks in advance


    Carlo
     
  2. NJDude

    NJDude Expert Licensed User

    thedesolatesoul and Carlo2015 like this.
  3. Carlo2015

    Carlo2015 Member Licensed User

    Thanks! I will give it a try as soon as i get hold of my laptop later.

    :)
     
  4. Carlo2015

    Carlo2015 Member Licensed User

    To answer my ucfirst question

    i came up with this. Hope this will help someone who is looking for same function

    Code:
    Sub ucfirst(str As StringAs String
        str = str.ToLowerCase
      
        
    Try
            
    Dim Length = str.Length As Int
           
            
    Dim firstchar = str.SubString2(0,1).ToUpperCase As String
          
            
    Return firstchar & str.SubString2(1, Length - 1)  
        
    Catch
            
    Return str
        
    End Try
    End Sub


    And I modified NJDude's function to fit my need (Thanks NJDude)

    Code:
    Sub PadNZeros(num As String, Length As Int) As String
        
    Dim Padding As String
        Length = 
    Abs(Length) 
        
    For I = 0 To Length
            Padding = Padding & 
    "0"
        
    Next
        num = Padding & num
        num = num.SubString2(num.Length - Length, num.Length)
      
        
    Return num
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice