Author Topic: Is there a way to change a bunch of strings at one time?  (Read 2012 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Is there a way to change a bunch of strings at one time?
« on: October 16, 2014, 03:20:20 AM »
For example
C1 > C12
C5 > C62
TOP > BOTT
...

AND SO ON

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is there a way to change a bunch of strings at one time?
« Reply #1 on: October 16, 2014, 03:55:35 AM »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a way to change a bunch of strings at one time?
« Reply #2 on: October 16, 2014, 03:59:42 AM »
Will the search string be the complete target string or will it be contained in the target string ( a substring ) ?
 
Will the search string and replacement string be string values or variables ?

The first thing you could do is build a reference list for your translations

I'll make some assumptions about your intent.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq translationList
  3.        (list (list "C1" "C12")
  4.              (list "C5" "C62")
  5.              (list "TOP" "BTM")
  6.              (list "SO" "ON")
  7.              
  8.        )
  9. )
  10.  
  11.  
  12. (defun getRef (key)
  13.   (cdr (assoc key translationList))
  14. )
  15.  
  16.  
  17. ;; Test the function just to be sure
  18. (getRef "CAT")  ;;==> nil
  19. (getref "TOP")  ;;==> ("BTM")
  20. (car (getRef "CAT") ) ;;==> nil
  21. (car (getRef "C1") )  ;;==> "C12"
  22.  
  23.  
  24.  
  25.  
  26. ;; Now write a tester
  27. (setq targetString "C5" )
  28. (if  (setq replacement (car (getRef targetString) ))
  29.   (setq targetString replacement)
  30. )  
  31.  
  32. (alert (strcat "targetString value is now\n" targetString))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is there a way to change a bunch of strings at one time?
« Reply #3 on: October 18, 2014, 04:15:00 AM »
While start to write a lisp, comes in mind it is very hard to do.
But when Kerry reply the post comes in mind the teacher while teaching me the lesson step by step.
Thanks Kerry for your very simple and easy way.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a way to change a bunch of strings at one time?
« Reply #4 on: October 18, 2014, 04:21:06 AM »
Thanks HasanCAD.
I teach the same way my brain usually works ... in little steps  :-)
and I do try very hard to keep stuff simple.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.