--- id: csharp-strings-access title: "C# Access Strings" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["IndexOf Substring", "string indexing C#", "C# 문자열 접근"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "strings", "indexing"] raw_sources: ["https://www.w3schools.com/cs/cs_strings_access.php"] applied_in: [] github_commit: "" --- # [[CSharp Access Strings]] ## 🎯 한 줄 통찰 (One-line insight) `myString[0]` reuses the identical square-bracket index syntax from C's raw char arrays and C++'s `std::string::operator[]`, 0-indexed exactly the same way — but C# then layers `IndexOf()` and `Substring()` on top as a matched PAIR designed to work together (`name.Substring(name.IndexOf("D"))` finds a position, then slices from it), a "search then slice" combo pattern this wiki hasn't seen expressed this explicitly in C/C++ (C++'s `std::string::find()` + `substr()` do the same job but the tutorial there never demonstrated them chained as a single idiom the way this C# chapter does). [S1] ## 🧠 핵심 개념 (Core concepts) - **`[]` indexing** — access a single character by index, 0-based: `myString[0]` is the first character. [S1] - **`.IndexOf(char)`** — returns the index position of the FIRST occurrence of a specified character/substring. [S1] - **`.Substring(startIndex)`** — extracts and returns a NEW string starting from the given index to the end. [S1] - **Combined idiom: search-then-slice** — `IndexOf()` locates a position, and that position is fed directly into `Substring()` to extract everything from that point onward (e.g. isolating a last name from a full name). [S1] ## 📖 세부 내용 (Details) - Basic indexing: `string myString = "Hello"; Console.WriteLine(myString[0]); // "H"` and `myString[1]; // "e"`. [S1] - Search: `string myString = "Hello"; Console.WriteLine(myString.IndexOf("e")); // 1`. [S1] - Combined search+slice: `string name = "John Doe"; int charPos = name.IndexOf("D"); string lastName = name.Substring(charPos); Console.WriteLine(lastName);` → `"Doe"`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **대괄호 인덱싱 문법은 C/C++와 동일**: `myString[0]`이 0부터 시작하는 인덱스로 문자에 접근하는 방식이 C 배열, C++의 `std::string::operator[]`와 차이가 없다는 점이 확인됨. [S1] - **IndexOf+Substring 조합 관용구가 명시적으로 제시됨**: C++도 `find()`+`substr()`로 동일한 일을 할 수 있었지만, Topic_CPP의 문자열 챕터에서는 두 메서드를 체이닝하는 관용구가 이렇게 명시적으로 다뤄지지 않았다는 점이 이번 챕터에서 새롭게 확인됨 — "찾고 나서 자르기"라는 하나의 패턴으로 제시됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) "John Doe"라는 전체 이름에서 "D"의 위치를 찾아 그 위치부터 Substring()으로 성(lastName)만 추출하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) Search-then-slice idiom combining IndexOf() and Substring() (C#): ```csharp string name = "John Doe"; int charPos = name.IndexOf("D"); // find position of "D" string lastName = name.Substring(charPos); // slice from that position -> "Doe" Console.WriteLine(lastName); ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.84 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C# Tutorial]] - **관련 개념:** [[CSharp Strings Interpol]], [[CSharp Strings Chars]], [[CPP Strings Access]] - **참조 맥락:** Strings 섹션 — Special Characters 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — C# Access Strings — https://www.w3schools.com/cs/cs_strings_access.php ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Access Strings" page (Astra wiki-curation, P-Reinforce v3.1 format).