## Hl7Message.setSegment() method

Sets or replaces a segment at the specified index. Only allows MSH header to be replaced as first segment. If index is a number and is larger than the length of the segments array, it will be appended as the last segment. If the index is a string, replaces the first segment with that name.

**Signature:**

```typescript
setSegment(index: number | string, segment: Hl7Segment): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| index | number \| string | The segment index or name |
| segment | [Hl7Segment](/content/docs/sdk/core.hl7segment) | The new segment to set |

**Returns:**

boolean

true if the segment was set, false otherwise

- [Hl7Message.setSegment() method](/content/docs/sdk/core.hl7message.setsegment#hl7messagesetsegment-method/index.html)  
- [Parameters](/content/docs/sdk/core.hl7message.setsegment#parameters/index.html)
