Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Quotes, apostrophes in data
Message
De
23/07/2001 20:37:12
Jason Dalio
Northern Interior Regional Health Board
Prince George, Colombie Britannique, Canada
 
 
À
23/07/2001 19:46:25
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00534017
Message ID:
00534193
Vues:
14
I'm at home (have to stop answering questions from home) with neither VB nor Access, so my code might be shaky but we'll try. As VBA has no Replace function all you can do is loop through the string and create the new string on the fly. Below i example code:

Public Function MakeNewString (InputString as String) as string
Dim sQuote As String, sDQuote As String
dim CurrentStringPos as long
dim LastStringPos as long
dim TempOutputString as string

MakeNewString = ""
LastStringPos = 0
sDQuote = Chr$(34)
sQuote = Chr$(39) & Chr$(39)
do while CurrentStringPos = instr(LastStringPos + 1, InputString, sDQuote)
TempOutputString = Mid$(InputString, LastStringPos + 1, CurrentStringPos _
- 1) & sQuote
MakeNewString = MakeNewString & TempOutputString
LastStringPos = CurrentStringPos + 1
loop
TempOutputString = Mid$(InputString, LastStringPos + 1)
MakeNewString = MakeNewString & TempOutputString
End function

Essentially, the code starts at the first char of the string and uses a boolean test of the instr function to determine if there are anymore "'s in the string. If there are it uses the mid$ to grab everything to the left of it, adds the '' and then resets the Pos counters to start searching the string again on the character to the right of the ". The final step is to grab everything from the right of the last " to complete the new string. One quick additional note: I tend to use a lot of variables and explicit assignments in my sample code. This code can be done more efficiently but I prefer to show things very detailed and explicity in sample code. Like I said, I couldn't test this at home but it should be fairly sound (provided I haven't made too many typos!).
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform