---
url: /flow/guide/scripting-reference/functions/string/stringreplacefirst.md
---

# StringReplaceFirst

## Declaration

`Function StringReplaceFirst( const S, OldPattern, NewPattern : string) : string`

### Example

```pascal
procedure OnMapEvent(var Value:Variant);
begin
 Value := StringReplaceFirst('abc#def#g','#','|'); //returns 'abc|def#g'
end;
```

## Description

Replaces the first occurrence of OldPattern with NewPattern in S string. OldPattern can be one or more characters. NewPattern can be one or more characters, or it can be blank which effectively removes the first occurrence of OldPattern.
