# str-replace()

## 용도 <a href="#use" id="use"></a>

특정 문자의 내용 중 일부 문자를 검색해 다른 문자로 대체하고자 할 경우 사용합니다.

## 사용법 <a href="#usage" id="usage"></a>

`str-replace()` 함수에 변경할 문자, 찾을 검색어, 변경할 문자 값을 전달합니다.

> str-replace($string:**string**, $search:**string**, $replace:**string**) → **string**

```javascript
@debug str-replace("string replace", " ", "-"); // "string-replace" 반환
@debug str-replace("top Left", " ");            // "topLeft" 반환
```

| 매개변수(parameter) | 유형(type) | 필수(required) | 기본 값(default) |
| :-------------: | :------: | :----------: | :-----------: |
|     $string     |  string  |      ✔︎      |               |
|     $search     |  string  |      ✔︎      |               |
|     $replace    |  string  |              |      `''`     |

## 로직 <a href="#logic" id="logic"></a>

`str-replace()` 유틸리티는 다음의 로직에 의해 작성되었습니다.&#x20;

```javascript
@function str-replace($string, $search, $replace: '') {
  $index: str-index($string, $search);

  @if $index {
    @return str-slice($string, 1, $index - 1) + $replace +
      str-replace(
        str-slice($string, $index + str-length($search)),
        $search,
        $replace
      );
  }

  @return $string;
}
```

1. 전달 받은 컬러 이름(`$name`)이 [ $colors 구성 변수](https://yamoo9.gitbook.io/scss-mixins/getting-started/configure#undefined)에 등록된 이름인지 검사
2. 컬러 이름이 컬러 구성표에 포함된 이름인 경우, `true` 반환
3. 컬러 이름이 컬러 구성표에 포함되지 않은 이름인 경우, `false` 반환

## 참고 <a href="#reference" id="reference"></a>

유틸리티 함수 로직에 사용된 Sass 빌트인 모듈은 다음과 같습니다.

* [@if / @else](https://sass-lang.com/documentation/at-rules/control/if)
* [str-index()](https://sass-lang.com/documentation/modules/string#index)
* [str-slice()](https://sass-lang.com/documentation/modules/string#slice)
* [str-length()](https://sass-lang.com/documentation/modules/string#length)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yamoo9.gitbook.io/scss-mixins/utilities/string/str-replace.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
