f.a.r.t. (stop laughing, it means 'find and replace text') :P

Author Message
core.ebusiness

  • Total Posts : 17
  • Scores: 0
  • Reward points : 0
  • Joined: 9/20/2010
  • Location: North Jersey
  • Status: offline
f.a.r.t. (stop laughing, it means 'find and replace text') :P Tuesday, September 21, 2010 9:20 AM (permalink)
0
http://pastebin.com/DYNUnzC2

basic find and replace text tool for checking a text/csv/etc document for chars or strings and replacing them accordingly. i use this script to check files for invalid characters such as the copyright symbol or trademark (symbols that we dont put in our database) and replace them with a null value (or a blank space depending on what i need). enjoy.

=)

 
#1
    core.ebusiness

    • Total Posts : 17
    • Scores: 0
    • Reward points : 0
    • Joined: 9/20/2010
    • Location: North Jersey
    • Status: offline
    Re:f.a.r.t. (stop laughing, it means 'find and replace text') :P Tuesday, February 01, 2011 2:43 PM (permalink)
    0
    so recently ive had the need to update/enhance this script a little bit. what i needed it to do is replace all non-alphanumeric chars with the exception of a few...and what ive mashed together from this, my original script - and another using a regexp global setting found here - and ive come up with this gem:

    http://pastebin.com/LwaHbcnY

    this code replaces all non-alphanumeric characters with the exception of the , @-_" and "\r" is to not replace line breaks. but my issue is this:

    right now it has to contain the specific file name. id like to use a wildcard for "any.csv" file in the "current dir". tried using the typical "*.csv" as well as a few other methods, but was unsuccessful. anyone offer some tips? :)
     
    #2
      core.ebusiness

      • Total Posts : 17
      • Scores: 0
      • Reward points : 0
      • Joined: 9/20/2010
      • Location: North Jersey
      • Status: offline
      Re:f.a.r.t. (stop laughing, it means 'find and replace text') :P Tuesday, February 01, 2011 3:35 PM (permalink)
      0
      oh, and just a few informational bits i forgot to include in my previous post (cant seem to locate the edit function?)
      this:
      oRE.Pattern = "[\W_]"
      is the same as this:
      oRE.Pattern = "[^a-z0-9A-Z]"
      not exactly sure how they equate, but i use the second method since its more familiar to me.
      also - the reason there are so many " in my string, its because i don't want the script to remove them, but you cant use the escape char like this:
      oRE.Pattern = "[^a-z0-9A-Z, @-_\r\"]"
      you have to quote the quotes to include them:
      oRE.Pattern = "[^a-z0-9A-Z, @-_\r""""]"
      (made me laugh a little when i tried it and it actually worked...)
      works on most file types - no xls.
      to alter the code to work for xml files, so it doesnt remove the tags, make the pattern look like this for example:
      oRE.Pattern = "[^a-z0-9A-Z, @-_\r""""<>/]"
       
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9