#17627 - 2002-02-19 07:29 AM
Character stripping
|
Mick Callaghan
Lurker
Registered: 2002-02-19
Posts: 2
Loc: Melbourne, Australia
|
Does anybody have any ideas on what I bet will be a really really simple job. Basically I want to strip sime punctuation marks ouut of a variable. ie : I want to get rid of the ":" from the @time so that I can create files with a time stamp as the suffix.$filename=@time ? $filename 10:08:45 I want this to read 100845
|
|
Top
|
|
|
|
#17629 - 2002-02-19 11:06 AM
Re: Character stripping
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
A very simple solution if you are using KiXtart version 4 is:
code:
$asTimeBits=Split(@TIME,":") $sFileName="" + $asTimeBits[0] + $asTimeBits[1] + $asTimeBits[2] ? $sFileName
|
|
Top
|
|
|
|
#17630 - 2002-02-20 12:52 AM
Re: Character stripping
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
If you need an UDF solution, I'm using this one since some times :First param is the text to change second param is the separator (can be anything, from 1 to x...x characters) third param (optional) is the string used to replace separators code:
Function TextReplace($sText,$sSeparator, optional $sNewSeparator) Dim $Stock dim $Element for each $Element in Split($sText,$sSeparator) If len($Stock)>0 $Stock=$Stock+""+$sNewSeparator+$Element else $Stock=$Element endif next $TextReplace=$Stock endfunction
[ 19 February 2002: Message edited by: Alex.H ]
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#17631 - 2002-02-19 03:24 PM
Re: Character stripping
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Or you could use the ever infamous "Squeeze" function from the function library:Break On ?"RealTime="@TIME ?"SqueezeTime=" Squeeze(@TIME,":") Exit 1 Function Squeeze($string1,$string2) while instr($string1,$string2) $string1 = substr($string1,1,instr($string1,$string2)-1) + substr($string1,instr($string1,$string2)+len($string2)) loop $squeeze = $string1 EndFunction
SqueezeTime ... hmmm ... I like the sounds of that ! -Shawn [ 19 February 2002: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#17632 - 2002-02-19 10:44 PM
Re: Character stripping
|
Mick Callaghan
Lurker
Registered: 2002-02-19
Posts: 2
Loc: Melbourne, Australia
|
Thanks All - thats great!!!!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 661 anonymous users online.
|
|
|