Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Attn Jezebel: Search and Replace in String

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eternally Grateful - 02 Feb 2005 01:37 GMT
Jezebel,

Your earlier response to my issue works perfectly by itself. But when I add
it to an IF statement, the macro completely runs over it bringing back a
negative response, therefore treating the line of code as if it had been
commented out.

Would you have any idea as to what the problem could be...

My code is...

       If InStr(1, MyData, Chr(150)) > 0 Then
           
           MyData = Replace$(OldData, Chr$(150), "-")
           
       End If

*******************************************************

em-dash is chr(150)

BTW, the string versions of these functions are about 10 times faster than
the variant equivalents --

MyData = Replace$(OldData, chr$(150), "-")

"Vince" <sdsad@fsd.com> wrote in message
news:uU2pIoBCFHA.244@TK2MSFTNGP10.phx.gbl...
> myData=Replace(myData,chr(40),"-")
>
> OR
> myData=Replace(myData,"¾","-")
>
> Is this what you want?
>
> Vince
>
> "Eternally grateful" <Eternally grateful@discussions.microsoft.com> wrote
> in
> message news:1D3B6AAD-28BA-4C32-A474-A934B6C114E0@microsoft.com...
>> Can anyone tell me if it is possible to perform a search and replace
> inside
>> of a string?
>>
>> I have a string called myData that contains an emdash that I need to
> change
>> into a hyphen and I cannot find a way to do this.
>>
>> Any assistance would be greatly appreciated.
>>
>> Thank you for taking them time to read this.




   
Jonathan West - 02 Feb 2005 01:39 GMT
Shouldn't that first line use OldData instead of MyData?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

> Jezebel,
>
[quoted text clipped - 46 lines]
>>>
>>> Thank you for taking them time to read this.
Jay Freedman - 02 Feb 2005 02:52 GMT
Besides that, the If is probably unnecessary. If the old string
doesn't contain any em dashes, the result of the Replace is the same
as the old string, so that's all you need. The only reason to have the
If statement would be that you don't want to assign anything to MyData
if there are no em dashes in OldData. I'll bet that isn't your
intention.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Shouldn't that first line use OldData instead of MyData?
>
[quoted text clipped - 48 lines]
>>>>
>>>> Thank you for taking them time to read this.
Jezebel - 02 Feb 2005 02:46 GMT
First, as Jonathan has picked up -- the function argument is MyData or
OldData or whatever variable you are using. The fact that you didn't get an
error on this means that you don't have an  'Option Explicit' statement at
the top of your code module. Put one in immediately, and set the option so
that it's automatic in future. You'll save yourself a heap of anguish.

However, a critical problem is that I led you astray. Chr$(150) is an EN
dash. EM dash is 151.

Also, there's no need for the IF statement. Replace looks for one string and
replaces it with another if found. If not found it does nothing.

> Jezebel,
>
[quoted text clipped - 46 lines]
>>>
>>> Thank you for taking them time to read this.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.