---
schema_version: "1"
id: 9edfdadf91ba9158ab156cbb7cdee46d1a84978ecebedfef44abde4fe833e05c
title: toBinary
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.4/dw-coercions-functions-tobinary.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.4/dw-coercions-functions-tobinary
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8b1b153e3370f1b65f907d3b9de2dc0a6c8eff0703ca60eda539fea18107fb2f
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
# toBinary

## [](#tobinary1)toBinary(str: String, encoding: String): Binary

指定されたエンコーディングを使用して ​`String`​ 値を ​`Binary`​ 値に変換します。

_DataWeave バージョン 2.4.0 で導入されました。_​

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>str</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Binary</code>​ 値に変換する ​<code>String</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>encoding</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>String</code>​ 値に適用するエンコーディング。JDK でサポートされているエンコーディングを受け入れます。たとえば、​<code>encoding</code>​ は Oracle JDK 8 と JDK 11 の基本および拡張エンコーディングセットの Java 正規名と別名を受け入れます。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、さまざまな入力での ​`toBinary`​ の動作を示します。 `application/dw`​ 形式の出力が生成されます。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
  'UTF-16Ex': toBinary("DW", "UTF-16"),
  'utf16Ex': toBinary("DW", "utf16"),
  'UnicodeBigEx': toBinary("DW", "UnicodeBig"),
  'UTF-32Ex': toBinary("DW", "UTF-32"),
  'UTF_32Ex': toBinary("DW", "UTF_32")
}
```

#### [](#出力)出力

```Json
{
  "UTF-16Ex": "/v8ARABX" as Binary {base: "64"},
  utf16Ex: "/v8ARABX" as Binary {base: "64"},
  UnicodeBigEx: "/v8ARABX" as Binary {base: "64"},
  "UTF-32Ex": "AAAARAAAAFc=" as Binary {base: "64"},
  UTF_32Ex: "AAAARAAAAFc=" as Binary {base: "64"}
}
```