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
Source Editor - Open Sour...
by
n7800
[
Today
at 05:13:12 am]
Form Positioning (Run & D...
by
Tony Stone
[
Today
at 03:28:03 am]
StrToInt not raising an e...
by
ALLIGATOR
[
Today
at 03:17:25 am]
Unselect all rows in stri...
by
Jonny
[
Today
at 01:07:15 am]
[solved] Issues was wrong...
by
What I can do
[
Today
at 01:03:09 am]
Specialisation doesn't se...
by
nixbody
[
Today
at 12:38:49 am]
User Domain
by
Remy Lebeau
[
Today
at 12:20:36 am]
Treeview: full-width back...
by
wp
[
Today
at 12:06:20 am]
visasession
by
Laksen
[
Today
at 12:03:45 am]
UADE Library
by
Gigatron
[February 06, 2025, 11:41:14 pm]
Please explain what is Po...
by
PascalDragon
[February 06, 2025, 11:03:56 pm]
Error, the IF function do...
by
wp
[February 06, 2025, 10:30:54 pm]
"set of": order of elemen...
by
PascalDragon
[February 06, 2025, 10:14:14 pm]
Compile App Error
by
eldonfsr
[February 06, 2025, 10:03:23 pm]
ellipse ? off topic
by
d2010
[February 06, 2025, 09:10:42 pm]
using RunCommand to wrap ...
by
MarkMLl
[February 06, 2025, 08:54:16 pm]
Telegram bots API Wrapper
by
Renat.Su
[February 06, 2025, 07:51:49 pm]
Custom self drawn compone...
by
wp
[February 06, 2025, 06:29:29 pm]
working on multiple proje...
by
TRon
[February 06, 2025, 05:39:14 pm]
Problema como barra de ro...
by
mfdzerohour
[February 06, 2025, 05:14:28 pm]
image processing library
by
JernejL
[February 06, 2025, 04:27:07 pm]
Reading and writing AVIF ...
by
Tomxe
[February 06, 2025, 02:34:13 pm]
Pointer and/xor set failu...
by
BrunoK
[February 06, 2025, 12:41:51 pm]
Dialogs and Windows PE
by
d2010
[February 06, 2025, 11:52:49 am]
What is more (memory) eff...
by
DragoRosso
[February 06, 2025, 11:51:34 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: String replace or add ' not " (Read 856 times)
eldonfsr
Hero Member
Posts: 531
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: 16516
Kallstadt seems a good place to evict Trump to.
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
But I am sure they don't want the Trumps back...
eldonfsr
Hero Member
Posts: 531
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: 1460
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: 16516
Kallstadt seems a good place to evict Trump to.
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
But I am sure they don't want the Trumps back...
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
String replace or add ' not "
TinyPortal
© 2005-2018