| 1. |
Solve : Sring handling problem? |
|
Answer» Hello, Beat me to it by a matter of seconds Gotta be quick over here Dave. Thanks for addition. I saw the space in the 2nd token but figured they could figure out how to strip it.Shouldn't that be second=%%C. Code: [Select]echo off for /f usebackq^ tokens^=1^*^ delims^=^" %%A in ("file.txt") do for /f "tokens=*" %%C in ("%%B") do ( set "first=%%A" set "second=%%C" ) echo %first% echo %second% pauseLemonilla, thank you for fixing my example. I would like to use a space for the delimiter. Unfortunately, this may be too difficult. Squashman, Thank you for offering another way. That is, going back one step and extracting the text form the file and splitting the text in one go. However, I notice that it only works if there is a space in the first path. There may be, in my case, where there is no space or more than one space in the first path and the script fails. As mentioned above, I might need to change my delimiter. I am not understanding you. It works with the example you provided. If it is not working then provide a non obfuscated example of your data that it is not working with.OK, yes it does work with the example I supplied. But, as I said if there are more or less spaces in the path it fails. I intended to enter more than one line in the file.txt file and process each line in turn. A couple of real examples: D:\MyProgs\DriveGleam\drivegleam.exe /startup "C:\Program Files (X86)\DropMyRights\DropMyRights.exe" "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe" Just to show a couple.Shouldn't have any problems with spaces as the code is using the double quote as the delimiter. But, you need to be consistent with your input. One example you just showed has no quotes.Thank you. I thought that script was using 2 spaces as the delimiter. Goes to show how well I understand batch scripting. I'll use double quotes. Quote from: Frank on December 17, 2014, 08:34:24 PM Thank you. I thought that script was using 2 spaces as the delimiter. Goes to show how well I understand batch scripting.I did specifically say in my first post I was using a double quote as the delimiter. Quote from: Frank on December 17, 2014, 08:34:24 PM Thank you. I thought that script was using 2 spaces as the delimiter. if you can control the delimiter and are using filename\paths then using a pipe character is a good choice as a delimiter. or a * or ? or < or > as none of them can be in a path\filename. Quotes are a poison character in batch scripts in many ways. Quote from: foxidrive on December 17, 2014, 11:26:04 PM if you can control the delimiter and are using filename\paths then using a pipe character is a good choice as a delimiter.I am in 100% agreement with you on that. It works flawlessly for us where I work. I do data automation for a living and we have all of our customers send in their data PIPE delimited. |
|