Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Replace the last occurrence of a string
[ All Languages » VB »  String]

Total Hit ( 3280)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Here is a one-liner that replaces the last occurrence of a substring in a string. It is slightly less efficient than using the InstrRev plus a Replace statement, but at least you can use it in-line inside another expression. And it is also one of the few occasions to use the StrReverse function, undoubtedly the least useful addition to the VBA language in years:

Click here to copy the following block
' replace only the LAST occurrence of a the SEARCH substring in SOURCE
' with the REPLACESTR string - search isn't case-sensitive
ReplaceLast = StrReverse(Replace(StrReverse(Source), StrReverse(Search), _
  StrReverse(ReplaceStr), , 1))


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.