Re: Will this SQL work to find records with hard returns in one of the text fields?
- From: "David W. Fenton" <dXXXfenton@xxxxxxxxxxxxxxxx>
- Date: Wed, 12 Oct 2005 22:23:01 -0500
MLH <CRCI@xxxxxxxxxxxxxx> wrote in
news:qj1rk1ti34dvk0dsh3qh5ghmrpf4ln9nsf@xxxxxxx:
>>> strName = StrIn
>>> For intX = 1 To Len(strName)
>>> strY = Mid(strName, intX, 1)
>>> If (Asc(strY) <> 13 And Asc(strY) <> 10) Then
>>> strNewName = strNewName & strY
>>> End If
>>> Next intX
>>> StripReturns = strNewName
>>
>>This is just ridiculously complex code.
>>
>>There's a VBA constant, vbCrLf, that you can use for this, and use
>>Instr to find the location of that 2-character string:
>>
>> Dim lngPosition As Long
>>
>> Do Until InStr(strTemp, vbCrLf) = 0
>> lngPosition = InStr(strTemp, vbCrLf)
>> If lngPosition = 0 Then
>> Exit Do
>> Else
>> strTemp = Mid(strTemp, 1, lngPosition - 1)
>> strTemp = strTemp & Mid(strTemp, lngPosition+2)
>> End If
>> Loop
>
> I can see your point. But one's 8-lines and the other's
> 9-lines = not a huge difference there. . . .
No, mine is 10 lines and yours is 12.
Mine is also faster, as it doesn't walk through the string character
by character, and has fewer calls to other functions. Mine could
also be reduced to 9 lines by combining the strTemp concatenations
into one line. Of course, yours could be reduced by two lines by
putting your If statement on one line.
> . . . I do like using
> the VBA constant. Gives me the feeling Microsoft's
> done some of the work for me.
That's what the constants are for.
My point is that you don't need to walk through the string character
by character, which is what I considered "convoluted" when you are
dealing with replacing a 2-character string.
And, of course, becasue of that, yours is not generalizable to
replacing any string of any length, precisely because it's assuming
two characters.
Mine also assumes 2 characters, but that can be fixed with this
change:
strTemp = strTemp & Mid(strTemp, lngPosition+Len(vbCrLf))
so that you'd replace vbCrLf with the variable you're passing in as
your search string.
Yours really can't be altered to fix that without major
re-engineering.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
.
- Follow-Ups:
- References:
- Will this SQL work to find records with hard returns in one of the text fields?
- From: MLH
- Re: Will this SQL work to find records with hard returns in one of the text fields?
- From: Salad
- Re: Will this SQL work to find records with hard returns in one of the text fields?
- From: David W. Fenton
- Re: Will this SQL work to find records with hard returns in one of the text fields?
- From: MLH
- Will this SQL work to find records with hard returns in one of the text fields?
- Prev by Date: Re: Composite Primary Key
- Next by Date: Re: Composite Primary Key
- Previous by thread: Re: Will this SQL work to find records with hard returns in one of the text fields?
- Next by thread: Re: Will this SQL work to find records with hard returns in one of the text fields?
- Index(es):
Relevant Pages
|