---
title: "JSStringGetUTF8CString(_:_:_:)"
framework: javascriptcore
role: symbol
role_heading: Function
path: "javascriptcore/jsstringgetutf8cstring(_:_:_:)"
---

# JSStringGetUTF8CString(_:_:_:)

Converts a JavaScript string into a null-terminated UTF-8 string, and copies the result into an external byte buffer.

## Declaration

```swift
func JSStringGetUTF8CString(_ string: JSStringRef!, _ buffer: UnsafeMutablePointer<CChar>!, _ bufferSize: Int) -> Int
```

## Parameters

- `string`: The source doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSStringRef.
- `buffer`: The destination byte buffer to copy a null-terminated UTF-8 representation of string into. On return, buffer contains a UTF-8 string representation of string. If bufferSize is too small, buffer contains only partial results. If buffer isn’t at least bufferSize bytes in size, the conversion results in undefined behavior.
- `bufferSize`: The size of the external buffer in bytes.

## Return Value

Return Value The number of bytes the system writes into buffer (including the null-terminator byte).

## See Also

### Accessing JavaScript String Information

- [JSStringGetLength(_:)](javascriptcore/jsstringgetlength(_:).md)
- [JSStringGetCharactersPtr(_:)](javascriptcore/jsstringgetcharactersptr(_:).md)
- [JSStringGetMaximumUTF8CStringSize(_:)](javascriptcore/jsstringgetmaximumutf8cstringsize(_:).md)
