Friday, 17 July 2020

Working with strings in Go

Strings are implemented as a reference type, though they're immutable.

String 


s := "This is in first line"
s += "\n"
s += "...and this is in the second line"

How do you write multiline strings in Go?

This raw quote (raw literal) does not parse escape sequences (\n would remain):

`line 1
line 2\n
line 3`

It is possible to use formatters though:

fmt.Sprintf(`a = %d`, 123)

Another option:

"line 1" +
"line 2" +
"line 3"



What is the difference between backticks (``) & double quotes (“”) in golang?

String Comparison - use == or !=

Slice string into letters

String Formatting 


s := fmt.Sprintf("a %s", "string")

Go by Example: String Formatting
Extracting substrings in Go

%x - formats value as HEX string with lowercase letters
%X - formats value as HEX string with uppercase letters

var n []byte = ...
s := fmt.Sprinf("%x", n) 

How to print struct variables in console? To print the name of the fields in a struct:

fmt.Printf("%+v\n", myStruct)


To convert string to byte array use:

s string
buffer := []byte(s)


fmt


fmt.Println("Table names:", tableNames)

SPACE character is automatically inserted between these two strings.

Golang - How to print the values of Arrays?

fmt.Printf("%v", projects)


fmt.Printf


%+v - prints struct’s field names (if value is a struct)





Go string = byte sequence, UTF-8 encoded
Unicode UTF-8 code point = 1-4 bytes (1 for ASCII)
rune = int32 => can store each UTF-8 code point 

Unicode string example: en dash & Chinese letter 

package main

import (
"fmt"
)

func main() {
s := "\u2013汉"
fmt.Printf("Character %s has %d bytes, %d UTF-8 code points", s, len(s), len([]rune(s)))
}

Output:

Character –汉 has 6 bytes, 2 UTF-8 code points


3 comments:

tutorialcup said...

Hi there to everybody, it’s my first go to see of this web site; this weblog consists of awesome and in fact good stuff for visitors. Hurrah, that’s what I was exploring for, what stuff! Existing here at this blog, thanks admin of this web site. You can also visit String Interview Questions for more TutorialCup. related information and knowledge.

Jason williams said...

Are you interested in any kinds of hacking services?
Feel free to contact TECHNECHHACKS.

For years now we’ve helped so many organizations and companies in hacking services.
TECHNECHHACKS is a team of certified hackers that has their own specialty and they are five star rated hackers.

We give out jobs to hackers (gurus only) to those willing to work, with or without a degree, to speed up the availability of time given to jobs!!

Thus an online binary decoding exam will be set for those who needs employment under the teams establishment.


we deal with the total functioning of sites like,


• SOCIAL MEDIA (Facebook, Twitter, Instagram, Snapchat, google hangout etc.)

• SCHOOL GRADES

• IOS/OS

• CREDIT SCORES

• BANK ACCOUNTS

• SPOUSES PHONE

Our special agents are five star rated agents that specializes in the following, and will specially be assigned to you for a special job well DONE.

• WESTERN UNION TRANSFER

• CREDIT CARDS INSTALLATION

• MONEY FLIPPING

• CRIMINAL RECORDS

• BTC RECOVERY

• BTC MINING

• BTC INVESTMENT

Thus bewere of scammers because most persons are been scammed and they ended up getting all solutions to their cyber bullies and attacks by US.

I am Jason williams one of the leading hack agent.

PURPOSE IS TO GET YOUR JOBS DONE AT EXACTLY NEEDED TIME REQUESTED!!!



And our WORK SUCCESS IS 100%!!!



We’re always available for you when you need help.

Contact or write us on:

Technechhacks@gmail.com

SIGNED....!

Jason. W

Technechhacks
2020©️All Right Reserved












Fixit said...

Hello all
am looking few years that some guys comes into the market
they called themselves hacker, carder or spammer they rip the
peoples with different ways and it’s a badly impact to real hacker
now situation is that peoples doesn’t believe that real hackers and carder scammer exists.
Anyone want to make deal with me any type am available but first
I‘ll show the proof that am real then make a deal like

Available Services

..Wire Bank Transfer all over the world

..Western Union Transfer all over the world

..Credit Cards (USA, UK, AUS, CAN, NZ)

..School Grade upgrade / remove Records

..Spamming Tool

..keyloggers / rats

..Social Media recovery

.. Teaching Hacking / spamming / carding (1/2 hours course)

discount for re-seller

Contact: 24/7

fixitrogers@gmail.com