Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.excel.programming > #110756

Re: Remove leading zeros from string

From GS <gs@v.invalid>
Newsgroups microsoft.public.excel.programming
Subject Re: Remove leading zeros from string
Date 2018-10-14 10:09 -0400
Organization A noiseless patient Spider
Message-ID <ppvimg$f8f$1@dont-email.me> (permalink)
References <dddc43bc-8bc0-4e02-93fc-83c322b486a1@googlegroups.com> <8467ae2e-0389-433a-964c-9be21000076b@googlegroups.com> <ppulof$8l4$1@dont-email.me> <cf9d42dc-47a2-4d25-bce8-33f212329577@googlegroups.com> <ppvhnl$99v$1@dont-email.me>

Show all headers | View raw


For example...


Function FilterString$(ByVal TextIn$, Optional IncludeChars$, _
                       Optional IncludeLetters As Boolean = True, _
                       Optional IncludeNumbers As Boolean = True)
' Filters out all unwanted characters in a string.
' Arguments:  TextIn          The string being filtered.
'             IncludeChars    [Optional] Any non alpha-numeric characters to 
keep.
'             IncludeLetters  [Optional] Keeps any letters.
'             IncludeNumbers  [Optional] Keeps any numbers.
'
' Returns:    String containing only wanted characters.
' Comments:   Works very fast using the Mid$() function over other methods.

Const sSource As String = "FilterString()"

  'The basic characters to always keep by default
  Const sLetters  As String = "abcdefghijklmnopqrstuvwxyz"
  Const sNumbers  As String = "0123456789"

  Dim i&, sKeepers$

  sKeepers = IncludeChars
  If IncludeLetters Then _
      sKeepers = sKeepers & sLetters & UCase(sLetters)
  If IncludeNumbers Then sKeepers = sKeepers & sNumbers

  For i = 1 To Len(TextIn)
    If InStr(sKeepers, Mid$(TextIn, i, 1)) Then _
      FilterString = FilterString & Mid$(TextIn, i, 1)
  Next
End Function 'FilterString()

In the IW:
  ?nopad_zeros(filterstring("Part# 0000006004",,false))
  Returns 6004

  ?nopad_zeros(filterstring("Part# 0000060040",,false))
  Returns 60040

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

Back to microsoft.public.excel.programming | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Remove leading zeros from string Tatsujin <tatsujin.3.r@gmail.com> - 2018-10-13 04:08 -0700
  Re: Remove leading zeros from string Claus Busch <claus_busch@t-online.de> - 2018-10-13 13:19 +0200
  Re: Remove leading zeros from string Ramon-México <cesaramon@gmail.com> - 2018-10-13 21:00 -0700
    Re: Remove leading zeros from string GS <gs@v.invalid> - 2018-10-14 01:55 -0400
      Re: Remove leading zeros from string Tatsujin <tatsujin.3.r@gmail.com> - 2018-10-14 02:33 -0700
        Re: Remove leading zeros from string GS <gs@v.invalid> - 2018-10-14 09:52 -0400
          Re: Remove leading zeros from string GS <gs@v.invalid> - 2018-10-14 10:09 -0400

csiph-web