Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
String replace or add ' not "
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
New Mac mini M4 - FPC 3.2...
by
derden
[
Today
at 04:26:31 pm]
How to hide IEEE754 limit...
by
wp
[
Today
at 03:55:45 pm]
Lowercase Drive in LAZ 4....
by
Martin_fr
[
Today
at 03:32:28 pm]
Some testing the water qu...
by
mdlueck
[
Today
at 03:19:39 pm]
Demo #3 of my "home grown...
by
TBMan
[
Today
at 03:05:57 pm]
Add new unit to a Lazarus...
by
Lulu
[
Today
at 02:58:02 pm]
Seems like good timing to...
by
mdlueck
[
Today
at 02:17:23 pm]
Lazarus Bugfix Release 4...
by
jwdietrich
[
Today
at 01:54:34 pm]
synedit
by
Martin_fr
[
Today
at 01:49:12 pm]
[SOLVED] How to update 'F...
by
Hartmut
[
Today
at 01:33:36 pm]
Porting PDF Viewer from D...
by
Boleeman
[
Today
at 12:38:46 pm]
Form scaling aspect ratio
by
Pe3s
[
Today
at 10:32:26 am]
This worries me about our...
by
zeljko
[
Today
at 09:25:47 am]
Help with search and repa...
by
avk
[
Today
at 07:09:59 am]
Variable "xyz" doesn't no...
by
Mr.Madguy
[
Today
at 06:22:15 am]
Problem Installing CHM He...
by
Curt Carpenter
[
Today
at 03:03:11 am]
EditorMacroScript did not...
by
jamie
[
Today
at 02:55:41 am]
Mapping Images Like Odome...
by
SandyG
[November 14, 2025, 11:53:01 pm]
Programmatic filtering in...
by
jamie
[November 14, 2025, 11:27:29 pm]
Problem with Qt5 on macOS
by
zeljko
[November 14, 2025, 10:39:24 pm]
Incompatible type in MTPr...
by
LemonParty
[November 14, 2025, 06:36:59 pm]
In fpcsrc, many places ca...
by
AlexTP
[November 14, 2025, 06:15:35 pm]
Postgres, ZEOS and Visual...
by
wp
[November 14, 2025, 05:57:25 pm]
[Solved] Process exited w...
by
d7_2_laz
[November 14, 2025, 05:14:08 pm]
AVRPascal – free code edi...
by
ackarwow
[November 14, 2025, 04:21:44 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: String replace or add ' not " (Read 1223 times)
eldonfsr
Hero Member
Posts: 553
String replace or add ' not "
«
on:
January 15, 2025, 10:23:59 pm »
I tried to replace or add double quotes to single quote but i don't get is way to replace
what i tried to do is validate register on table so need to send keyfields but whe i made locate i need separate them for fieldname and fieldvalue..
Code: Pascal
[Select]
[+]
[-]
Procedure
TForMMain
.
MigrateTable
(
OldTbl
:
TBufDataSet
;
NewTbl
:
TBufDataSet
;
KeyField
:
Array
of
String
)
;
Var
Fldname
:
String
;
cf
,
i
:
Integer
;
begin
if
(
NewTbl
.
Active
=
false
)
then
begin
NewTbl
.
Open
;
end
;
oldtbl
.
First
;
while
not
oldtbl
.
EOF
do
begin
if
(
length
(
KeyField
)
=
1
)
then
begin
Fldname
:
=
''
''
+
KeyField
[
0
]
+
''
''
;
if
(
newtbl
.
Locate
(
FldName
,
Oldtbl
.
FieldByName
(
FldName
)
.
asString
,
[
]
)
)
then
begin
newtbl
.
edit
;
end
else
begin
newtbl
.
Append
;
end
;
end
else
begin
Fldname
:
=
''
+
KeyField
[
0
]
;
for
i
:
=
1
to
length
(
KeyField
)
-
1
do
begin
Fldname
:
=
Fldname
+
chr
(
39
)
+
','
+
chr
(
39
)
+
KeyField
[
i
]
+
chr
(
39
)
;
end
;
// show fldname but its contain " not single quote ans lazarus need..
if
(
newtbl
.
Locate
(
FldName
,
Arrayof
(
Oldtbl
.
FieldByName
(
KeyField
[
0
]
)
.
asString
+
,
[
]
)
)
then
begin
newtbl
.
edit
;
end
else
begin
newtbl
.
Append
;
end
;
end
;
newtbl
.
Append
;
for
cf
:
=
0
to
oldtbl
.
FieldCount
-
1
do
begin
fldname
:
=
oldtbl
.
FieldDefs
[
cf
]
.
DisplayName
;
newtbl
.
FieldByName
(
fldname
)
.
Value
:
=
oldtbl
.
FieldByName
(
fldname
)
.
Value
;
end
;
newtbl
.
Post
;
oldtbl
.
Next
;
end
;
NewTbl
.
SaveToFile
(
oldtbl
.
FileName
)
;
end
;
code
]
Logged
Thaddy
Hero Member
Posts: 18364
Here stood a man who saw the Elbe and jumped it.
Re: String replace or add ' not "
«
Reply #1 on:
January 16, 2025, 06:14:41 am »
Something like this? (untested)
Code: Pascal
[Select]
[+]
[-]
{$mode objfpc){$H+}
uses
sysutils
;
var
s
:
string
=
'test"me"a bit "more" or "something"'
;
begin
s
:
=
stringreplace
(
s
,
#34
,
#39
,
[
rfReplaceAll
]
)
;
end
.
#39 avoids ''''
«
Last Edit: January 16, 2025, 06:26:27 am by Thaddy
»
Logged
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.
eldonfsr
Hero Member
Posts: 553
Re: String replace or add ' not "
«
Reply #2 on:
January 16, 2025, 03:18:17 pm »
Yes but #34 and #39 is same both are " and i need '
Logged
Remy Lebeau
Hero Member
Posts: 1566
Re: String replace or add ' not "
«
Reply #3 on:
January 16, 2025, 04:49:23 pm »
Quote from: eldonfsr on January 16, 2025, 03:18:17 pm
Yes but #34 and #39 is same both are " and i need '
No, #34 is " (double quote) and #39 is ' (single quote).
You could also use:
Code: Pascal
[Select]
[+]
[-]
s
:
=
StringReplace
(
s
,
'"'
,
''
''
,
[
rfReplaceAll
]
)
;
But, if this is not accomplishing what you need, then you need to explain better what you are actually trying to do.
Also, have a look at
QuotedStr()
or
TStringHelper.QuotedString()
or
TStringList.DelimitedText
.
«
Last Edit: January 16, 2025, 04:54:29 pm by Remy Lebeau
»
Logged
Remy Lebeau
Lebeau Software
- Owner, Developer
Internet Direct (Indy)
- Admin, Developer (
Support forum
)
Thaddy
Hero Member
Posts: 18364
Here stood a man who saw the Elbe and jumped it.
Re: String replace or add ' not "
«
Reply #4 on:
January 16, 2025, 05:09:22 pm »
Tnx for pointing that out, Remy.
(the # notation saves you from using '''' etc)
«
Last Edit: January 16, 2025, 05:14:17 pm by Thaddy
»
Logged
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
String replace or add ' not "
TinyPortal
© 2005-2018