words

package module
v0.0.0-...-2462f00 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 4 Imported by: 1

README

words

Simple helper package for strings and words.

English word set

I found this awesome github repo https://github.com/dwyl/english-words from which i downloaded words.txt containing huge amount of english words.

Features

  • get text length
  • reverse text
  • check for palindrome (case-sensitive or case-insensitive) (word that reads same when written backwards, like "bob")
  • check for anagram (two different words contain same letters in different order, example: "I am Lord Voldemort" is an anagram of "Tom Marvolo Riddle")
  • check for pangram (text contains all 26 letters atleast once)
  • check and count vowels or consonants
  • find all words that can be written with given letters (for example: with letters "tra" you can write (atleast) words "rat" and "tar"

Usage

This package have not been released as go package so follow instructions below on how to use this.

To use this package, download or clone this repo next to golang project where you are going to use this. For example, if you have folder named "go-projects" and in there you have golang project "project-a" and you want to add this package to it you should have this package next to "project-a" like following:

├── go-projects
│   ├── words
│   ├── project-a

Then at root of project-a folder run command

go mod edit -replace github.com/Korppi/words=../words

After this run go mod tidy command

go mod tidy

Your go.mod file should have something similar in it:

replace github.com/Korppi/words => ../words

require github.com/Korppi/words v0.0.0-00010101000000-000000000000

In case there are problems, you can refer to official documentation https://go.dev/doc/tutorial/call-module-code

Example of usage of words package

package main

import (
    "fmt"

    "github.com/Korppi/words"
)

func main() {
    message := words.Reverse("123")
    fmt.Println(message)
}

This should output following:

321

For example i have used this package here: https://github.com/Korppi/words-cli

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountConsonants

func CountConsonants(s string) (count int)

Returns count of consonants in given string s

func CountOccurences

func CountOccurences(s string, substring string) int

Return how many times substring occurs in s

func CountVowels

func CountVowels(s string) (count int)

Returns count of vowels in given string s

func IsAnagram

func IsAnagram(s1 string, s2 string) bool

Check if s1 and s2 are anagrams (both have same letters in different order) Example of anagrams, words "rat" and "tar" are anagrams

func IsConsonant

func IsConsonant(r rune) bool

Return true if r is consonant

func IsPalindrome

func IsPalindrome(s string) bool

Check if word is case-insensitive palindrome. Example: ABba returns true

func IsPalindromeCaseSensitive

func IsPalindromeCaseSensitive(s string) bool

Check if word is case-sensitive palindrome. Example: ABba returns false

func IsPangram

func IsPangram(s string) bool

Returns true if world contains every letter in alphabets atleast once

func IsVowel

func IsVowel(r rune) bool

Return true if r is vowel

func Reverse

func Reverse(s string) (reversed string)

Reverse given string s

func SearchPossibleWords

func SearchPossibleWords(letters string) (result []string)

func WordLength

func WordLength(s string) (count int)

Return word length

Types

This section is empty.

Jump to

Keyboard shortcuts

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