# Need help with fixed length strings

**URL:** <https://forum.hdfgroup.org/t/need-help-with-fixed-length-strings/4745>\
**Category:** HDF5 Library\
**Created:** [August 16, 2018, 6:52pm UTC](https://forum.hdfgroup.org/t/need-help-with-fixed-length-strings/4745 "2018-08-16T18:52:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arthurobdfv](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/a/6f9a4e/32.png) [@arthurobdfv](https://forum.hdfgroup.org/u/arthurobdfv)\
**Post date:** [August 16, 2018, 6:52pm UTC](https://forum.hdfgroup.org/t/need-help-with-fixed-length-strings/4745/1 "2018-08-16T18:52:26Z")

</div>

i’m having trouble when putting values on a string column of a compound dataset i’ve created, i want it to be a fixed length column that has the size equal to the biggest length between all the values i’m writing (this number i can get easily), the problem happens when i write it because i get strange characters on the value column on HDFView, when i make a string column with variable length it works fine using Marshal.StringToHGlobalAnsi() storing an IntPointer to my struct and store it, but when i change it to a fixed length it seems to break everything

Here is the struct i’m using:

struct OpcString  
{  
public UInt64 dt;  
public Int64 qlt;  
public bool isNull;  
public IntPtr vl;  
}

and this is the part of the code i create the datatype of the dataset

```
 H5DataTypeId stringTypeId = H5T.create(H5T.CreateClass.STRING, maxLen);

  var size = H5T.getSize(stringTypeId);
  
  OpcString opcHelper = new OpcString();
  H5DataTypeId dataTypeId = H5T.create(H5T.CreateClass.COMPOUND, (Marshal.SizeOf(opcHelper)));
  H5T.insert(dataTypeId, "Timestamp", 0, new H5DataTypeId(H5T.H5Type.NATIVE_ULLONG));
  H5T.insert(dataTypeId, "Quality", 8, new H5DataTypeId(H5T.H5Type.NATIVE_LONG));
  H5T.insert(dataTypeId, "IsNull", 16, new H5DataTypeId(H5T.H5Type.NATIVE_HBOOL));
  H5T.insert(dataTypeId, "Value", 20, stringTypeId);

```

Here is the conversion that i use to recieve a string and storing as an intptr on the hdf5 so i get rid of the encoding issues

```
static IntPtr ConvertTo(string s)
{
  var x = Marshal.StringToHGlobalAnsi(s);
  return x;
}

```

I really don’t knonw where the problem is because i can’t seem to understand how strings work
