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
Debian removes FPC/Lazaru...
by
dbannon
[
Today
at 12:16:00 am]
'Rounding' to (say) 5 DP
by
LV
[February 17, 2026, 11:51:29 pm]
Is it possible to create ...
by
LeP
[February 17, 2026, 11:20:42 pm]
StrMath.pas a String Numb...
by
Bart
[February 17, 2026, 10:56:34 pm]
Status of FPC 3.4.0 or FP...
by
PascalDragon
[February 17, 2026, 09:25:01 pm]
lazarus project
by
dseligo
[February 17, 2026, 09:17:17 pm]
MVP made easier.
by
cdbc
[February 17, 2026, 09:16:07 pm]
A diary project with SQLi...
by
cdbc
[February 17, 2026, 09:03:25 pm]
[ANN] fpGUI Toolkit v2.0....
by
PascalDragon
[February 17, 2026, 08:49:17 pm]
Form has no Taskbar entry...
by
n7800
[February 17, 2026, 07:48:59 pm]
DCPcrypt v2.0.6 — Cryptog...
by
Ten_Mile_Hike
[February 17, 2026, 07:40:22 pm]
[SOLVED] Lazarus recompil...
by
creaothceann
[February 17, 2026, 07:37:12 pm]
4.4 messed with the proje...
by
QEnnay
[February 17, 2026, 07:26:00 pm]
Anyone else getting a tro...
by
dseligo
[February 17, 2026, 07:24:37 pm]
Duplicated icon in the Wi...
by
n7800
[February 17, 2026, 06:11:54 pm]
[AGGPas] Difference betwe...
by
cdbc
[February 17, 2026, 05:02:28 pm]
[SOLVED] Statically linki...
by
marcov
[February 17, 2026, 04:56:09 pm]
pas2js WebAssembly SQLite...
by
PierceNg
[February 17, 2026, 03:32:46 pm]
My AGGPas examples
by
Roland57
[February 17, 2026, 02:10:03 pm]
Datatype of Fields in sql...
by
Dzandaa
[February 17, 2026, 01:46:59 pm]
TurboBird IBX
by
valdir.marcos
[February 17, 2026, 10:38:16 am]
Delphi Magazine issues 1-...
by
valdir.marcos
[February 17, 2026, 10:37:33 am]
We are starting to use La...
by
dbannon
[February 17, 2026, 06:25:04 am]
Fast Canvas Library V1.05...
by
backprop
[February 17, 2026, 03:19:31 am]
TurboBird for FireBird 5
by
maurog
[February 17, 2026, 02:28:10 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: String replace or add ' not " (Read 1302 times)
eldonfsr
Hero Member
Posts: 557
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: 18729
To Europe: simply sell USA bonds: dollar collapses
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
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...
eldonfsr
Hero Member
Posts: 557
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: 1572
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: 18729
To Europe: simply sell USA bonds: dollar collapses
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
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
String replace or add ' not "
TinyPortal
© 2005-2018