2009-04-28 5 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를 허용 이러한 엑스트라를 구현하고 싶습니다,하지만 난 그들이 정확히 모르겠어요. : ~ offset, length는 약간 명백합니다 ... 부분 문자열입니다. 그러나 첫 번째 것이 무엇인지 확실하지 않습니다.

아이디어가 있으십니까?

빌리 3

답변

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

즉, 검색 및 대체 : 숫자는 끝 문자열의에서 작업? –

+0

아, 이제 알 겠어 :) 고마워! –

+0

MSDOS 2 이후 COMMAND.COM의 생존자로서 CMD.EXE는 훨씬 더 즐겁습니다. 대화 형 명령 프롬프트에서 변수 대체와 같은 것을 직접 테스트하고 증명할 수있는 것이 좋습니다. 예전에는 환경 변수 대체와 같은 특정 작업은 프롬프트가 아니라 배치 파일에서만 수행되었습니다. – RBerteig