기억해야 할 문자열 조작 방법
이 블로그에서는 기술 인터뷰에서 이러한 질문에 쉽게 대답할 수 있도록 암기해야 할 가장 일반적인 문자열 조작 방법을 나열합니다.

함께 묶기
저는 최근 인터뷰에서 이 코딩 문제를 질문받았습니다. 그렇게 긴장하지 않고 일주일 전에 데이터 구조와 알고리즘만 공부했다면 상당히 쉬웠습니다.
// Write a function called "abbreviate" that outputs a string.
// Given a string, keep the first and last letter and replace the letters in between by the length.
// e.g. internationalization => i18n, localization => l10n
원하는 출력을 얻기 위해 어떤 방법을 사용해야 하는지 기억하는 데 평소보다 더 오래 걸렸습니다. 물론 핸디
console.log
를 사용하여 몇 가지 가능한 방법을 테스트할 수 있었지만 솔루션을 얻기 전에 여전히 온라인에서 특정 방법을 검색해야 했습니다. 아래는 내가 생각해 낸 것입니다.const abbreviate = (input) => {
return input.length < 3 ? input : [input[0], input.length - 2, input[input.length-1]].join('');
};
const result = abbreviate("internationalization");
console.log(result);
이것은 차례로 이러한 일반적인 문자열 조작 방법을 머리 속에 새겨 넣는 방법을 재평가하게 했습니다. 결과적으로, 나는 그것을 돕기 위해 아래 치트 목록을 작성하고 있습니다.
일반적인 문자열 조작 방법

str.길이
let str = "zen";
console.log(str.length); // outputs 3
charAt(인덱스)
string.length - 1
let str = 'Strings';
console.log(str.chatAt(3)); // outputs i
console.log(str.charAt(6)); // outputs s
연결(문자열)
const str1 = 'purple';
const str2 = 'balloon';
console.log(str1.concat(str2)); // outputs 'purple balloon'
// or by inserting string variables into another string to achieve cleaner code
const str1 = 'purple';
const str2 = 'balloon';
const sampleStr = `${purple} ${balloon}`;
console.log(sampleStr); // outputs purple balloon
포함(문자열)
const str = 'what up';
console.log(str.includes('what')); // true
console.log(str.includes('down')); // false
일치(정규식 문자열)
const firstName = "Matt";
const badFirstName = "Matthew4";
const nameRegex = /^[a-zA-Z]+$/
console.log(firstName.match(nameRegex)); // true
console.log(badFirstName.match(nameRegex)); // false
바꾸기(문자열ToBeReplaced, 문자열추가)
const userInput = '917 716 4543';
console.log(userInput.replace(' ', '-')); // 917-716-4543
분할(문자열)
const seeyou = "See You";
const seeYouSplit = see.split(' ');
console.log(seeYouSplit); // ["See", "You"];
console.log(seeYouSplit[0]); // "See"
부분 문자열(인덱스, 인덱스)
const goodbye = 'Goodbye Friend';
console.log(goodbye.substring(1, 4); // ood
소문자()/대소문자()
const firstName = "Yani";
console.log(firstName.toUpperCase()); // YANI
손질()
const strWithSpace = 'Yani ';
console.log(strWithSpace.trim()); // outputs 'Yani'
결론
이 블로그의 주요 내용은 데이터 구조 및 알고리즘과 같은 더 복잡한 주제를 시작하기 전에 먼저 기본 지식을 강화하는 것이 항상 현명하다는 것입니다. 이 블로그가 도움이 되었기를 바랍니다!
Reference
이 문제에 관하여(기억해야 할 문자열 조작 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/yani82/string-manipulation-methods-to-memorize-49e0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)