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で許可されているこれらの追加機能を実装したいのですが、正確にはわかりません。:〜offset、lengthは少し明白です...サブストリング。しかし、最初のものが何であるかはわかりません。

何か案は?

ビリー3

4

1 に答える 1

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
于 2009-04-28T01:36:14.493 に答える