| 1. |
Solve : using " as delim? |
|
Answer» I want to make simple converter and what i need to do: One more thing if coming to replacing characters, would there be way to replace whole string of characters into single char (for using few types of delimiters)? The syntax for string replacement is: Inside a loop where you are using delayed expansion (and hence using exclamation marks for variables) Code: [Select]set string=!string:A=B! Or elsewhere using percent signs Code: [Select]set string=%string:A=B% A is any sequence of one or more characters that you wish to search for in %string% and B is zero or more characters that you wish to put in A's place. Thus if %string1% is: I like cats set string2=%string1:cat=dog% would result in %string2% now containing I like dogs Notice that I used a NEW string (string2) in the SET statement. If you use the same variable name (e.g. set string=%string:hot=cold%) the string in the variable is modified but if you use a new variable (e.g. set newstring=%oldstring:man=woman%) then a new string is formed reflecting the change and the old string is preserved. If the replacement consists of a zero length string (i.e. nothing) then the search term is deleted so that if you did this Code: [Select]set string1=Mary had a little lamb set string2=%string1:little =% then you are searching string1 for little followed by one space and replacing it with nothing (there is nothing between the equals sign and the right-hand variable DELIMITER) and string 2 is therefore: Mary had a lamb Quote from: me, above A is any sequence of one or more characters that you wish to search for in %string% and B is zero or more characters that you wish to put in A's place. Note that if either sequence contains one or more of certain special control characters e.g. < > & % ! (there are more) then you have to take certain PRECAUTIONS to avoid the script barfing (crashing) at that point. |
|