StringReplace/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: StringReplace/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # StringReplace | |
| 2 | + | ||
| 3 | + | Flags: | |
| 4 | + | ||
| 5 | + | | Flag | Wert | | |
| 6 | + | |--------------|------| | |
| 7 | + | | rfReplaceAll | 0 | | |
| 8 | + | | rfIgnoreCase | 1 | | |
| 9 | + | ||
| 10 | + | Syntax: | |
| 11 | + | ||
| 12 | + | ``` pascal | |
| 13 | + | Neuerstring := StringReplace(Originalstring, | |
| 14 | + | String oder Zeichen das ersetzt werden soll, | |
| 15 | + | String oder Zeichen, das stattdessen eingefügt werden soll, | |
| 16 | + | Ein Flag oder beide Flags in eckigen Klammern); | |
| 17 | + | ``` | |
| 18 | + | ||
| 19 | + | # Anwendungsbeispiele | |
| 20 | + | ||
| 21 | + | ## Beispiel 1 | |
| 22 | + | ||
| 23 | + | Entfernt alle Steuerzeichen aus einem String: | |
| 24 | + | ||
| 25 | + | ``` pascal | |
| 26 | + | function funAlleSteuerzeichenEntfernen(strUebergabe: string): string; | |
| 27 | + | var | |
| 28 | + | wrdI: word; | |
| 29 | + | ||
| 30 | + | begin | |
| 31 | + | ||
| 32 | + | Result := strUebergabe; | |
| 33 | + | ||
| 34 | + | for wrdI := 0 to 31 do | |
| 35 | + | Result := StringReplace(Result, Chr(wrdI), '', [rfReplaceAll]); | |
| 36 | + | ||
| 37 | + | end; | |
| 38 | + | ``` | |
| 39 | + | ||
| 40 | + | ## Beispiel 2 | |
| 41 | + | ||
| 42 | + | Entfernt alle Steuerzeichen außer dem Steuerzeichen Tab aus einem String: | |
| 43 | + | ||
| 44 | + | ``` pascal | |
| 45 | + | function funAlleSteuerzeichenAusserTabEntfernen(strUebergabe: string): string; | |
| 46 | + | var | |
| 47 | + | wrdI: word; | |
| 48 | + | ||
| 49 | + | begin | |
| 50 | + | ||
| 51 | + | Result := strUebergabe; | |
| 52 | + | ||
| 53 | + | for wrdI := 0 to 31 do | |
| 54 | + | begin | |
| 55 | + | if wrdI = 9 then // filtert auf das Tabzeichen #9 | |
| 56 | + | continue; // springt direkt zum Schleifenkopf | |
| 57 | + | Result := StringReplace(Result, Chr(wrdI), '', [rfReplaceAll]); | |
| 58 | + | end; | |
| 59 | + | ||
| 60 | + | end; | |
| 61 | + | ``` | |
| 62 | + | ||
| 63 | + | ## Beispiel 3 | |
| 64 | + | ||
| 65 | + | Ignoriert Gross und Kleinschreiben in der Source. | |
| 66 | + | ||
| 67 | + | ``` pascal | |
| 68 | + | var | |
| 69 | + | s: String; | |
| 70 | + | begin | |
| 71 | + | ... | |
| 72 | + | s:= StringReplace(s, 'CbA', 'AbC', [rfReplaceAll, rfIgnoreCase]); | |
| 73 | + | ``` | |
| 74 | + | ||
| 75 | + | --- | |
| 76 | + | *From the Free Pascal wiki, page "StringReplace/de", as it stood on 2020-04-08 after a change by Mathias, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
