AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

replace string with spaces?

Ein Thema von direktor · begonnen am 19. Jan 2020 · letzter Beitrag vom 20. Jan 2020
Antwort Antwort
direktor

Registriert seit: 5. Apr 2014
22 Beiträge
 
#1

replace string with spaces?

  Alt 19. Jan 2020, 05:12
Hello,

I have another problem, how to pass the Space in string that I want to replace?

For example I want to find string 'this is just a test' and replace it with 'this is not a test'. Problem is Delphi will find only first word 'this' - everything after space is ignored. How do I make it find full string not that it stops at space? Or I'm using Delphi version which is too low? Should I use Unicode string compare?

'this is something else' - delphi will stop here because 'this' is contained here and 'is something else' it treats like it doesn't even exist because of space between

'this is just a test' - but I want to change this line of text down below, the whole text including spaces

How to do? StringReplace doesn't work.

Thanks.
  Mit Zitat antworten Zitat
hhcm

Registriert seit: 12. Feb 2006
Ort: Wegberg
310 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: replace string with spaces?

  Alt 19. Jan 2020, 07:43
Try this
Chris
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.635 Beiträge
 
Delphi 12 Athens
 
#3

AW: replace string with spaces?

  Alt 19. Jan 2020, 10:24
Please give us a small test program that shows the error. Also mention the Delphi version you are using.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
direktor

Registriert seit: 5. Apr 2014
22 Beiträge
 
#4

AW: replace string with spaces?

  Alt 19. Jan 2020, 12:10
Uwe there is no error. Just doesn't work like it's suppose to. It can't replace text with spaces, only can replace the first word matched, anything after space is not replaced - as a result it replaces wrong string that begins with the same word but text after first space is different. I'm using Delphi 6, but I have Delphi XE8 also installed and can be used. Thanks.
  Mit Zitat antworten Zitat
direktor

Registriert seit: 5. Apr 2014
22 Beiträge
 
#5

AW: replace string with spaces?

  Alt 19. Jan 2020, 12:16
Try this:

tmpstr.loadfromfile('index.html);
StringReplace(tmpstr.Text,'Electronics online shop','Electronic offline brick shop',[rfReplaceAll]);

This code will result in replacing every string that begins with word Electronics, because it can't handle spaces. I want to replace only exact string 'Electronics online shop' with spaces included.
  Mit Zitat antworten Zitat
DieDolly

Registriert seit: 22. Jun 2018
2.175 Beiträge
 
#6

AW: replace string with spaces?

  Alt 19. Jan 2020, 12:17
Zitat:
This code will result in replacing every string that begins with word Electronics, because it can't handle spaces.
StringReplace can handle spaces.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz