zoukankan      html  css  js  c++  java
  • [唐胡璐]VBS技巧 Pad Number String with Zeroes(在字符串左侧补0)

     '******************************************************************************* 
    'Description : Pads a number with zeroes on the left, according to the expected maximum length of the numbers in the list. ' 

    'Purpose : To keep a number list sorted properly, as with a file list (001, 002,..., 010, and not 1, 10, 11,..., 2, 20). ' 

    'Arguments : intCurrentNum (the current number to be padded) 
                'intMaxNumInList (the top number in the list) 

    'Note: The arguments are always taken in absolute values 

    'Returns : The padded intCurrentNum (for example, If 1 and 9999 are sent to the function, the result will be 0001) ' 

    '*******************************************************************************  
    PublicFunction PadNumber(ByVal intCurrentNum, ByVal intMaxNumInList) 
       
    'Validates the arguments - if invalid then it returns the value as is     
        If (NotIsNumeric(intCurrentNum) OrNotIsNumeric(intMaxNumInList)) Then         
            PadNumber = intCurrentNum         
            ExitFunction     
        EndIf    
         
        If (Abs(intCurrentNum) >= Abs(intMaxNumInList)) Then         
            PadNumber = intCurrentNum         
            ExitFunction     
        EndIf     
        
        PadNumber = String(len(CStr(Abs(intMaxNumInList)))-len(CStr(Abs(intCurrentNum))), "0") _  
                     & CStr(Abs(intCurrentNum)) 
                       
    EndFunction


    '*******************************************************************************  
    'Msgbox PadNumber(4, 34567)    'Returns 00004 
    'Msgbox PadNumber(-4, 34567)   'Returns 00004  
    'Msgbox PadNumber(4, -34567)   'Returns 00004 
    'Msgbox PadNumber(34567, 4)    'Returns 34567 
    'Msgbox PadNumber(4, 9)        'Returns 4 
    'Msgbox PadNumber("Hello", 9999) 'Returns Hello

  • 相关阅读:
    联赛模拟测试22 D. 简单计算
    联赛模拟测试22 B. 分组配对 倍增+二分
    斜率优化DP总结
    洛谷 P5490 【模板】扫描线
    容斥原理学习笔记
    联赛模拟测试20 C. Weed 线段树
    联赛模拟测试20 B. Walk (建图)
    联赛模拟测试20 A. Simple (数学)
    洛谷 P2617 Dynamic Rankings 树套树
    社区团购模式
  • 原文地址:https://www.cnblogs.com/yongfeiuall/p/4134201.html
Copyright © 2011-2022 走看看