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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
multitask question
by
d2010
[
Today
at 10:44:34 pm]
Minimal IPC approach?
by
MarkMLl
[
Today
at 09:45:35 pm]
Errors linking the projec...
by
Grahame Grieve
[
Today
at 09:41:59 pm]
[solved] is there a non v...
by
Martin_fr
[
Today
at 09:13:11 pm]
Custom TRichMemo
by
What I can do
[
Today
at 09:10:10 pm]
IDE crashes and takes so ...
by
Martin_fr
[
Today
at 08:49:04 pm]
Newbie in Web Programming...
by
Nicole
[
Today
at 08:44:50 pm]
Compiling Lazarus from so...
by
TRon
[
Today
at 07:55:37 pm]
Macos Sequoia Lazarus 3.8...
by
ChrisR
[
Today
at 07:34:39 pm]
Planet generator(raylib)
by
Lulu
[
Today
at 07:29:54 pm]
Good online resource to l...
by
Thaddy
[
Today
at 06:41:21 pm]
TPaintbox picture disappe...
by
TRon
[
Today
at 06:31:33 pm]
login_tty and openpty are...
by
Fred vS
[
Today
at 06:19:14 pm]
ShowModal has a bug in Li...
by
TRon
[
Today
at 04:14:31 pm]
BGRABitmap can't compile
by
Khrys
[
Today
at 03:43:59 pm]
Why isn't Lazarus / Free ...
by
silvercoder70
[
Today
at 02:46:40 pm]
Lazarus Release Candidate...
by
dbannon
[
Today
at 02:02:57 pm]
Linux Laz Packages have i...
by
dbannon
[
Today
at 01:56:35 pm]
Is there a chart displayi...
by
simone
[
Today
at 10:19:27 am]
How to re use a process
by
Thaddy
[
Today
at 10:10:46 am]
Helping beginners
by
Thaddy
[
Today
at 09:15:26 am]
[SOLVED] Application stil...
by
d2010
[
Today
at 07:01:19 am]
TListView - please advis...
by
TRon
[April 29, 2025, 09:49:00 pm]
$CODEPAGE + LCL = Incorre...
by
Thaddy
[April 29, 2025, 06:47:53 pm]
SOLVED: Warning: "crtbegi...
by
Thaddy
[April 29, 2025, 06:43:37 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: String replace or add ' not " (Read 1041 times)
eldonfsr
Hero Member
Posts: 543
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: 16832
Ceterum censeo Trump esse delendam
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
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.
eldonfsr
Hero Member
Posts: 543
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: 1504
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: 16832
Ceterum censeo Trump esse delendam
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
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
String replace or add ' not "
TinyPortal
© 2005-2018