Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to present string operations, e.g. string replace, by math notations

I attempt to describe an algorithm in the paper, and the algorithm is about string replace operation. The algorithm is complex, so a simple example is given instead as follows:

For a given number serial, all "1" will be replaced by "a"

How to present the procedure in math notation for an abstract, and general reason?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’m not sure if that’s what you were asking, but I’m assuming you want to write a program where you can assign different operations to math symbols, e.g.

Serial("1234") + 'a'

Should result in Serial("a234").

You can achieve this in Kotlin by using operator overloading. That means if you add a function to class Serial named plus and give it the replacement logic, you can "add" ‘a’ to your Serial and it will return a new serial with the ‘1’ replaced:

data class Serial(val raw: String) {
    operator fun plus(replacement: Char) : Serial {
        return Serial(raw.replace('1', replacement))
    }
}

val s = Serial("1234")
println(s + 'a')

Depending on your programming language, operator overloading is possible or not.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading