그래서 내 C # 프로젝트에 몇 가지 파일 확장자가 있고 파일 이름이있는 경우 파일 이름에서 제거해야합니다.
지금까지 하위 문자열이 파일 이름에 있는지 확인할 수 있다는 것을 알고 있습니다.
if (stringValue.Contains(anotherStringValue))
{
// Do Something //
}
그래서 말이 stringValue
이고 test.asm
포함 된 .asm
경우 .asm
에서 제거하고 싶습니다 stringValue
.
어떻게 할 수 있습니까?
Path
라이브러리 와 결합 된 "블랙리스트"접근 방식을 원하는 경우 :
// list of extensions you want removed
String[] badExtensions = new[]{ ".asm" };
// original filename
String filename = "test.asm";
// test if the filename has a bad extension
if (badExtensions.Contains(Path.GetExtension(filename).ToLower())){
// it does, so remove it
filename = Path.GetFileNameWithoutExtension(filename);
}
처리 된 예 :
test.asm = test
image.jpg = image.jpg
foo.asm.cs = foo.asm.cs <-- Note: .Contains() & .Replace() would fail
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다