HockeyFan Posted December 7, 2011 Share Posted December 7, 2011 Hello! Can someone point me in the right direction? I need to trim the leading zero's off of a numeric string. For example: I'm pulling the following sample information from a log file: 0000982 and would like to display it as 982. Yes, I have read the Help File, especially the "string" and "Stringtrim" fuctions for help, but the problem is that there is not always 4 leading zero's. I was thinking I would have to evaluate each number starting from the left and delete it if it was equal to zero. I just need to know where to start and I should be able to take it from there. Thanks for any help! Link to comment Share on other sites More sharing options...
UEZ Posted December 7, 2011 Share Posted December 7, 2011 (edited) Try this: $string = "00000012345054321" $new = StringReplace($string, StringRegExpReplace($string, "[^0].*", ""), "") MsgBox(0, "Test", $new) Br, UEZ Edited December 7, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 7, 2011 Moderators Share Posted December 7, 2011 HockeyFan, This seems to work quite well: Global $aList[3] = [0000982, 00009082, 9082] For $i = 0 To UBound($aList) - 1 $sRet = StringRegExpReplace($aList[$i], "^0*(d+)", "$1") ConsoleWrite($sRet & @CRLF) Next SRE explanation: ^0* - Any number of zeros starting at the beginning (d+) - Capture any digits following - obviously starting from anything other than a zero Does it work for you? M23 Xandy 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted December 7, 2011 Share Posted December 7, 2011 @M23: ^0*(d+) that's what I searched for... Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Exit Posted December 7, 2011 Share Posted December 7, 2011 keep it simple ! $n1 ="0000982 " $n = $n1+0 MsgBox(0,"",$n) Xandy and Laurynelis 2 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
UEZ Posted December 7, 2011 Share Posted December 7, 2011 Too simple Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
guinness Posted December 7, 2011 Share Posted December 7, 2011 (edited) Another way is using Number(). MsgBox(0, "", Number("0000982")) Edited December 7, 2011 by guinness Xandy 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
HockeyFan Posted December 7, 2011 Author Share Posted December 7, 2011 UEZ,Thank you! Thats basically all I need. ..although, the "[^0].*" paramater confuses me a bit Link to comment Share on other sites More sharing options...
HockeyFan Posted December 7, 2011 Author Share Posted December 7, 2011 M23,Thank you...this also works very well for me. As with UEZ's posting, I am a bit confused about the the "^0*(d+)" paramater. Thank you so much for explaining this!!!!! Link to comment Share on other sites More sharing options...
HockeyFan Posted December 7, 2011 Author Share Posted December 7, 2011 forumer100,Never looked at it that way, but I like it...very simple!Thank you! Link to comment Share on other sites More sharing options...
HockeyFan Posted December 7, 2011 Author Share Posted December 7, 2011 guinness, I looked at the Number() function, but didnt think it applied to this situation. I should have at least tried it. Thanks for bringing it to my attention! Link to comment Share on other sites More sharing options...
HockeyFan Posted December 7, 2011 Author Share Posted December 7, 2011 Thank you ALL for your reply's...I learned a little something more today! Cheers!! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 7, 2011 Moderators Share Posted December 7, 2011 HockeyFan, I think we all did. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SD097 Posted May 4 Share Posted May 4 Int("0000000000321") does the same. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now