Text

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 1 Imported by: 1

README

Go Go Report card GoDoc

golang-stringbuilder

A string builder that has similar capabilities as the one from C#. The goal is to have a straightforward API that lets you work with strings easily.

Install

To install the package, call:

go get -u github.com/linkdotnet/golang-stringbuilder

Next import the package:

import ( "github.com/linkdotnet/golang-stringbuilder" )

Quickstart

The API derives from the C# StringBuilder. You can easily append strings or single runes.

func main() {
	sb := Text.StringBuilder{}
	sb.Append("Hello")
	sb.Append(" ")
	sb.Append("World")
	fmt.Println(sb.ToString())
}

Also more advanced use cases where you want to insert an arbitrary word at an arbitrary position are possible.

sb := NewStringBuilderFromString("Hello World")
sb.Insert(5, " my dear")
output := sb.ToString() // Hello my dear World

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StringBuilder

type StringBuilder struct {
	// contains filtered or unexported fields
}

func NewStringBuilder

func NewStringBuilder(initialCapacity int) *StringBuilder

Creates a new instance of the StringBuilder with preallocated array

func NewStringBuilderFromString added in v0.2.0

func NewStringBuilderFromString(text string) *StringBuilder

Creates a new instance of the StringBuilder with a preallocated text

func (*StringBuilder) Append

func (s *StringBuilder) Append(text string)

Appends a text to the StringBuilder instance

func (*StringBuilder) AppendLine

func (s *StringBuilder) AppendLine(text string)

Appends a text and a new line character to the StringBuilder instance

func (*StringBuilder) AppendRune

func (s *StringBuilder) AppendRune(char rune)

Appends a single character to the StringBuilder instance

func (*StringBuilder) AsRune added in v0.3.0

func (s *StringBuilder) AsRune() []rune

Returns the string builder as a rune-slice

func (*StringBuilder) Clear added in v0.2.0

func (s *StringBuilder) Clear()

Removes all characters from the current instance. This sets the internal size to 0. The internal array will stay the same.

func (*StringBuilder) FindAll added in v0.4.0

func (s *StringBuilder) FindAll(text string) []int

Returns all occurrences of the given text in the string builder. Returns an empty if no occurrence found.

func (*StringBuilder) FindFirst added in v0.4.0

func (s *StringBuilder) FindFirst(text string) int

Returns the first occurrence of the given text in the string builder. Returns -1 if not found

func (*StringBuilder) FindLast added in v0.4.0

func (s *StringBuilder) FindLast(text string) int

Returns the last occurrence of the given text in the string builder. Returns -1 if not found

func (*StringBuilder) Insert

func (s *StringBuilder) Insert(index int, text string) error

func (*StringBuilder) Len

func (s *StringBuilder) Len() int

Returns the current length of the represented string

func (*StringBuilder) Remove

func (s *StringBuilder) Remove(start int, length int) error

func (*StringBuilder) RuneAt added in v0.3.0

func (s *StringBuilder) RuneAt(index int) rune

Gets the rune at the specific position

func (*StringBuilder) ToString

func (s *StringBuilder) ToString() string

Returns the represented string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL