# tensorflow::ops::Substr Class Reference

# tensorflow::
ops::
Substr

`
#include <string_ops.h>
`


Return substrings from
`
https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor
`
of strings.

## Summary


For each string in the input
`
https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor
`
, creates a substring starting at index
`
pos
`
with a total length of
`
len
`
.


If
`
len
`
defines a substring that would extend beyond the length of the input string, or if
`
len
`
is negative, then as many characters as possible are used.


A negative
`
pos
`
indicates distance within the string backwards from the end.


If
`
pos
`
specifies an index which is out of range for any of the input strings, then an
`
InvalidArgumentError
`
is thrown.


`
pos
`
and
`
len
`
must have the same shape, otherwise a
`
ValueError
`
is thrown on Op creation.


* NOTE *
:
`
https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr
`
supports broadcasting up to two dimensions. More about broadcasting
[here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)

*** ** * ** ***

<br />


Examples


Using scalar
`
pos
`
and
`
len
`
:


```
input = [b'Hello', b'World']
position = 1
length = 3
```

<br />


```
output = [b'ell', b'orl']
```

<br />


Using
`
pos
`
and
`
len
`
with same shape as
`
input
`
:


```
input = [[b'ten', b'eleven', b'twelve'],
         [b'thirteen', b'fourteen', b'fifteen'],
         [b'sixteen', b'seventeen', b'eighteen']]
position = [[1, 2, 3],
            [1, 2, 3],
            [1, 2, 3]]
length =   [[2, 3, 4],
            [4, 3, 2],
            [5, 5, 5]]
```

<br />


```
output = [[b'en', b'eve', b'lve'],
          [b'hirt', b'urt', b'te'],
          [b'ixtee', b'vente', b'hteen']]
```

<br />


Broadcasting
`
pos
`
and
`
len
`
onto
`
input
`
:


```
input = [[b'ten', b'eleven', b'twelve'],
         [b'thirteen', b'fourteen', b'fifteen'],
         [b'sixteen', b'seventeen', b'eighteen'],
         [b'nineteen', b'twenty', b'twentyone']]
position = [1, 2, 3]
length =   [1, 2, 3]
```

<br />


```
output = [[b'e', b'ev', b'lve'],
          [b'h', b'ur', b'tee'],
          [b'i', b've', b'hte'],
          [b'i', b'en', b'nty']]
```

<br />


Broadcasting
`
input
`
onto
`
pos
`
and
`
len
`
:


```
input = b'thirteen'
position = [1, 5, 7]
length =   [3, 2, 1]
```

<br />


```
output = [b'hir', b'ee', b'n']
```

<br />


Raises:


- `
  ValueError
  ` : If the first argument cannot be converted to a [Tensor](https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of `
  dtype string
  ` .
- `
  InvalidArgumentError
  ` : If indices are out of range.
- `
  ValueError
  ` : If `
  pos
  ` and `
  len
  ` are not the same shape.

<br />


Args:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- input: [Tensor](https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of strings
- pos: Scalar defining the position of first character in each substring
- len: Scalar defining the number of characters to include in each substring

<br />


Optional attributes (see
`
https://www.tensorflow.org/versions/r2.6/api_docs/cc/struct/tensorflow/ops/substr/attrs#structtensorflow_1_1ops_1_1_substr_1_1_attrs
`
):

- unit: The unit that is used to create the substring. One of: `
  "BYTE"
  ` (for defining position and length by bytes) or `
  "UTF8_CHAR"
  ` (for the UTF-8 encoded Unicode code points). The default is `
  "BYTE"
  ` . Results are undefined if `
  unit=UTF8_CHAR
  ` and the `
  input
  ` strings do not contain structurally valid UTF-8.

<br />


Returns:

- `
  https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output
  ` : [Tensor](https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of substrings

<br />

| ### Constructors and Destructors ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1ac4ec231f379a3a957a1ba6c388900d2e (const :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input pos, :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input len) ` ||
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1ad8326181a5399cf82aef5d7e4d9b925b (const :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input pos, :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input len, const https://www.tensorflow.org/versions/r2.6/api_docs/cc/struct/tensorflow/ops/substr/attrs#structtensorflow_1_1ops_1_1_substr_1_1_attrs & attrs) ` ||

| ### Public attributes ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1a5cebdcec605f165be72c6ccb0b0a7b6c ` | ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation ` |
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1a833ab93a8bd8153ad683227af6205edd ` | ` :: https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output ` |

| ### Public functions ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1a3a2b4eaf7158fcdda9d4b5e3012ed9c0 () const ` | ` ::tensorflow::Node * ` |
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1ae833d53311bfbb74a3c86b93f99c5027 () const ` | ` ` |
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1a001cd1f5803fc422a0b6fa274ca5b0eb () const ` | ` ` |

| ### Public static functions ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr_1a5ab53f27d3a07b25ad2b97cbaaa7747f (StringPiece x) ` | ` https://www.tensorflow.org/versions/r2.6/api_docs/cc/struct/tensorflow/ops/substr/attrs#structtensorflow_1_1ops_1_1_substr_1_1_attrs ` |

| ### Structs ||
|---|---|
| [tensorflow:: ops:: Substr:: Attrs](https://www.tensorflow.org/versions/r2.6/api_docs/cc/struct/tensorflow/ops/substr/attrs) | Optional attribute setters for [Substr](https://www.tensorflow.org/versions/r2.6/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr) . |

## Public attributes

### operation

```
Operation operation
```

### output

```
::tensorflow::Output output
```

## Public functions

### Substr

```
 Substr(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input pos,
  ::tensorflow::Input len
)
```

### Substr

```
 Substr(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input pos,
  ::tensorflow::Input len,
  const Substr::Attrs & attrs
)
```

### node

```
::tensorflow::Node * node() const 
```

### operator::tensorflow::Input

```
 operator::tensorflow::Input() const 
```

### operator::tensorflow::Output

```
 operator::tensorflow::Output() const 
```

## Public static functions

### Unit

```
Attrs Unit(
  StringPiece x
)
```