2009-04-28 59 views
1

我一直在编写一个应用程序,它需要在文件中扩展环境字符串。

为此,我可以使用标准的Windows API函数,ExpandEnvironmentStrings: http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx

我确实有与功能的一些问题,但。 第一: The size of the lpSrc and lpDst buffers is limited to 32K.

下一页:Note that this function does not support all the features that Cmd.exe supports. For example, it does not support %variableName:str1=str2% or %variableName:~offset,length%.

我想实现这些额外的cmd.exe允许的,但我不知道他们是什么。 :〜偏移量,长度有点明显......子串。但不知道第一个是什么。

任何想法?

Billy3

回答

5

它是字符串替换。

基本上,如果variableName设置为"I am three",那么"%variableName:three=four%"生成"I am four"(双引号输入更好的格式,它们不构成字符串的一部分)。

C:\Documents and Settings\Administrator>set x=I am three 

C:\Documents and Settings\Administrator>echo %x% 
I am three 

C:\Documents and Settings\Administrator>echo %x:three=four% 
I am four 

您也可以使用空字符串(明显)取代,并从字符串的开始(不那么明显)取代:

C:\Documents and Settings\Administrator>echo %x:three=% 
I am 

C:\Documents and Settings\Administrator>echo %x:*am=I am not% 
I am not three 

此外,子变体是Pythonesque在负

C:\Documents and Settings\Administrator>echo %x:~,4% 
I am 

C:\Documents and Settings\Administrator>echo %x:~-5% 
three 
+0

也就是说,搜索并替换:数字从结束的字符串的工作? – 2009-04-28 01:37:29