From e03adcac215b852f54a9ca8af9e0dd5f12f628dc Mon Sep 17 00:00:00 2001 From: hamza-m-masood Date: Thu, 18 Jul 2024 08:59:00 +0100 Subject: [PATCH] added diagram --- public/images/posts/go-string.svg | 4 ++++ src/content/posts/{strings-in-go.md => strings-in-go.mdx} | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 public/images/posts/go-string.svg rename src/content/posts/{strings-in-go.md => strings-in-go.mdx} (89%) diff --git a/public/images/posts/go-string.svg b/public/images/posts/go-string.svg new file mode 100644 index 0000000..1a69d4a --- /dev/null +++ b/public/images/posts/go-string.svg @@ -0,0 +1,4 @@ + + + +
...
...
h
h
e
e
l
l
l
l
o
o
,
,
w
w
o
o
r
r
l
l
d
d
...
...
data
data
len 12
len 12
s
s
data
data
len 5
len 5
hello
hello
data
data
len 5
len 5
world
world
Text is not SVG - cannot display
\ No newline at end of file diff --git a/src/content/posts/strings-in-go.md b/src/content/posts/strings-in-go.mdx similarity index 89% rename from src/content/posts/strings-in-go.md rename to src/content/posts/strings-in-go.mdx index b960cc4..27944c8 100755 --- a/src/content/posts/strings-in-go.md +++ b/src/content/posts/strings-in-go.mdx @@ -12,9 +12,8 @@ Strings in Go are represented as Unicode. Unicode represents numbers that are bi In order to make programs more efficient, we don't want to refer to every character all the time with more bytes (Unicode), since many programs will primarily use English characters (ASCII characters). There is an efficient way of encoding Unicode called UTF-8, which is a compact way of representing Unicode in bytes. -{{< notice "note" >}} -Strings are physically the UTF-8 encoding of Unicode, also known as bytes in Go. -{{< /notice >}} + +Strings are physically the UTF-8 encoding of Unicode, also known as bytes in Go. A rune is a synonym for int32 (32-bit integer), also known as Unicode. A byte is a synonym for uint8 (8-bit integer). @@ -47,7 +46,7 @@ world := s[7:] ``` Here is the graphical view of the above code: -{{< image src="images/strings.png" caption="" alt="alter-text" height="" width="" position="center" command="fill" option="q100" class="img-fluid" title="image title" webp="false" >}} +![Alt text here](/images/posts/go-string.svg) s is a string descriptor. A descriptor is not a pointer; it describes something and has a pointer within it. The descriptor also includes the length of the string. Also, note that the end of the string does not have a null byte like in other programming languages.