mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Add common StringReplace function
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user