Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!ub!uhura.cc.rochester.edu!vdra_ltd From: vdra_ltd@uhura.cc.rochester.edu (Valerie Drake) Newsgroups: comp.lang.pascal Subject: Re: Dose anybody have space det. code!!!!!!!!! Message-ID: <13646@ur-cc.UUCP> Date: 26 Apr 91 01:52:55 GMT References: <1991Apr22.060051.2238@nuchat.sccsi.com> Organization: University of Rochester - Rochester, New York Lines: 74 In ricki@martha.informatik.rwth-aachen.de (Richard Breuer) writes: >robby@nuchat.sccsi.com (Robert Oliver Jr.) writes: >>dose any body have some code that can detect a space in a string[40] and replace it with a -, but if there is not a space then dont do anything ? >>any help would be greatlee appreated. >Try this (Turbo Pascal): >--- schanipp schanapp -------------------------------------------------------- >procedure cb(var s: string40); >var > p: integer; >begin > { Calculate the position of the first space. 0, when there is none } > p:=pos(' ',s); > { Substitute it } > if (p>0) then s[p] := '-' >end; >--- schanipp schanapp -------------------------------------------------------- >I did not test it, but it should run. >Bye, Ricki. This example only works if there is ONE space! Here is an example to replace all spaces with a "-": ==== Schnip ================================================================== PROCEDURE replaceSpaces(var s:string); CONST SPACE = #32; DASH = #45; VAR p : BYTE; BEGIN p := pos(SPACE,s); WHILE (p > 0) DO BEGIN s[p] := DASH; p := pos(SPACE,s); END; END; (* or more generally *) FUNCTION replaceAnyChar(s:STRING; target,replacement : char): STRING; VAR P : BYTE; TString : String; begin TString := s; p := pos(target,TString); WHILE (p > 0) DO BEGIN TString[p] := replacement; p := pos(target,TString); END; return(TString); end; ====== Schnip ============================================================== The second one will be more general and will replace any character with any other, as well as leaving the original string intact if necessary. Hope that helps even more :=>. Lee -- | | +--+ +--+ o | Carpe Diem, Seize the DAY! | ////// | |\/ .\/. \/| o| vdra_ltd@uhura.cc.rochester.edu | /_ _\ | | )) /\ (( | o | Val & Lee Drake (The Fish Faces) +--,,,,----U----,,,,--+ |/\+--+ +--+/\| | | University of Rochester