# Help with my string type

**URL:** <https://discourse.julialang.org/t/help-with-my-string-type/10743>\
**Category:** New to Julia\
**Created:** [May 6, 2018, 4:56pm UTC](https://discourse.julialang.org/t/help-with-my-string-type/10743 "2018-05-06T16:56:52Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [May 6, 2018, 4:56pm UTC](https://discourse.julialang.org/t/help-with-my-string-type/10743/1 "2018-05-06T16:56:52Z")

</div>

Hi there,

I’m trying to implement a new string type consisting only of the characters [A-Z] and [0-9]:

```julia
abstract type AbstractMyString <: AbstractString end

struct MyString <: AbstractMyString
    str::String
    MyString(str) = begin
        ismatch(CSE, str) || error("string contains illegal characters")
        return new(str)
    end
end

const CSE = r"^.([A-Z]|[0-9])+$"

```

The problem I have is that I want `MyString` to work in functions that expect `String`. For example, I get the following error:

```julia
a = MyString("ASD1")
"Error showing value of type MyString:
ERROR: you must implement endof(MyString)

```

Which can be remedied by preventing the REPL from trying to print `a`, using a semi colon.

I thought that I could declare everything to be a subtype of `AbstractString` (as I cannot declare it to be subtype of `String`) and expect that everything that works with `AbstractString` to work with `MyString`. Where did I go wrong? How can I inherit the things that work with `AbstractString`?

---

_[View the full topic](https://discourse.julialang.org/t/help-with-my-string-type/10743)._
