{"id":1045,"date":"2021-01-12T10:44:00","date_gmt":"2021-01-12T17:44:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1045"},"modified":"2021-01-08T10:50:47","modified_gmt":"2021-01-08T17:50:47","slug":"extending-end-of-line","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2021\/01\/12\/extending-end-of-line\/","title":{"rendered":"Extending end of line"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In Xojo EndOfLine is two things<br>One is a global method and the other a Class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because of how the compiler works it realizes when you mean each one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a line of code like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var eol as EndOfLine<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">EndOfLine can, in that context, ONLY be a TYPE name. So the compiler knows you mean the EndOfLine class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But when you do<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim eol as EndOfLine = EndOfLine<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">it knows the FIRST one is the TYPE, the class, and the second HAS to be something that returns a value &#8211; in this case the method named EndOfLine. (And this design is something you can also use in your own code)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What this means is that since EndOfLine is also a CLASS it can be extended. And that makes it possible to add things like a Length function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public Function Length(extends e as EndOfLine) as integer\n  \n  Dim s As String = e\n  \n  Return s.length\n  \nEnd Function\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And there you go. Now you can write code like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var position as integer = otherString.IndexOf(EndOfLine)\nvar leftChars as string = otherString.left(position)\nvar eol as EndOfLine = EndOfLine\nvar rest as string = otherString.Middle(position + eol.length)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And NOT have to convert the EndOfLine into a string to get the length<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Xojo EndOfLine is two thingsOne is a global method and the other a Class. Because of how the compiler works it realizes when you mean each one. In a line of code like EndOfLine can, in that context, ONLY be a TYPE name. So the compiler knows you mean the EndOfLine class. But when &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2021\/01\/12\/extending-end-of-line\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Extending end of line&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1045","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=1045"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1045\/revisions"}],"predecessor-version":[{"id":1046,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1045\/revisions\/1046"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}