Let's say for example that I have one string, like this:
<h1>Hello World!</h1>
What Go code would be able to extract Hello World!
from that string? I'm still relatively new to Go. Any help is greatly appreciated!
Let's say for example that I have one string, like this:
<h1>Hello World!</h1>
What Go code would be able to extract Hello World!
from that string? I'm still relatively new to Go. Any help is greatly appreciated!
There are lots of ways to split strings in all programming languages.
Since I don't know what you are especially asking for I provide a sample way to get the output you want from your sample.
In the above code you trim
<h1>
from the left of the string and</h1>
from the right.As I said there are hundreds of ways to split specific strings and this is only a sample to get you started.
Hope it helps, Good luck with Golang :)
DB
If the string looks like whatever;START;extract;END;whatever you can use this:
What happens here is it will find first index of START, adds length of START string and returns all that exists from there until first index of END.
Read up on the strings package. Have a look into the SplitAfter function which can do something like this:
That should produce a slice something like:
"[", "this][", "is my][", "string]"
. Using further functions for Trimming you should get your solution. Best of luck.Just had a similar problem, only that I did not know if my input string s contained any or even multiple pairs of the START or STOP characters! So my general solution is:
In the strings pkg you can use the Replacer to great affect.
Go play!