V
V
v- death2015-11-03 01:13:39
PHP
v- death, 2015-11-03 01:13:39

How to remove comma at the end of a line?

Hello. There is a line


(' ' , ' '), (' ' , ' '),

This string is stored in redis.
I write the logs like this, and then I send the pack to the database as a demon. But for the query to work, you need to remove the comma from the end of the string.
If it's not difficult, can you give an example code?
Thanks in advance.
We need an analogue of the PHP function substr

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Solomennikov, 2015-11-03
@vGrabko99

To begin with, I would recommend using the official documentation, by the way, it even rises locally.
Packages/strings/func TrimRight, link to TrimRight, package strings - TrimRight
English words that you write in Russian, at least put in double quotes, if you are too lazy to write in eng, this increases the readability of your question and understanding.
It assumes that "(' ' , ' '), (' ' , ' ')," is indeed a string.

package main

import (
  "fmt"
  "strings"
)

func main() {
  var s = "(' ' , ' '), (' ' , ' '),"
  fmt.Println(strings.TrimRight(s, ","))
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question