Add common StringReplace function

This commit is contained in:
Adrian Gallagher
2017-08-21 14:50:22 +10:00
parent 65f3a25888
commit 0fea98857c
3 changed files with 29 additions and 2 deletions

View File

@@ -159,6 +159,11 @@ func TrimString(input, cutset string) string {
return strings.Trim(input, cutset)
}
// ReplaceString replaces a string with another
func ReplaceString(input, old, new string, n int) string {
return strings.Replace(input, old, new, n)
}
// StringToUpper changes strings to uppercase
func StringToUpper(input string) string {
return strings.ToUpper(input)

View File

@@ -310,6 +310,28 @@ func TestTrimString(t *testing.T) {
}
}
// ReplaceString replaces a string with another
func TestReplaceString(t *testing.T) {
t.Parallel()
currency := "BTC-USD"
expectedOutput := "BTCUSD"
actualResult := ReplaceString(currency, "-", "", -1)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'", expectedOutput, actualResult,
)
}
currency = "BTC-USD--"
actualResult = ReplaceString(currency, "-", "", 3)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'", expectedOutput, actualResult,
)
}
}
func TestRoundFloat(t *testing.T) {
t.Parallel()
originalInput := float64(1.4545445445)

View File

@@ -2,9 +2,9 @@ package bittrex
import (
"log"
"strings"
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
@@ -34,7 +34,7 @@ func (b *Bittrex) Run() {
continue
}
currencies = append(currencies,
strings.Replace(exchangeProducts[x].MarketName, "-", "", -1))
common.ReplaceString(exchangeProducts[x].MarketName, "-", "", -1))
}
err = b.UpdateAvailableCurrencies(currencies)
if err != nil {