Skip to content

Instantly share code, notes, and snippets.

@georgebent
Last active June 17, 2023 16:03
Show Gist options
  • Save georgebent/a51a267416f393e3a5939bf2ad73610c to your computer and use it in GitHub Desktop.
Save georgebent/a51a267416f393e3a5939bf2ad73610c to your computer and use it in GitHub Desktop.
Golang line convert: "1 / 3500 then go to Point_282" >>> 282 (get numcer from end)
package main
import (
"fmt"
"os"
"regexp"
"strconv"
)
func main() {
content, err := os.ReadFile("input.txt")
if err != nil {
fmt.Println("Помилка при читанні файлу:", err)
return
}
re := regexp.MustCompile(`Point_(\d+)`)
matches := re.FindAllStringSubmatch(string(content), -1)
var result []int
for _, match := range matches {
lastDigitStr := match[1]
lastDigit, err := strconv.Atoi(lastDigitStr)
if err != nil {
fmt.Println("Помилка при конвертації числа:", err)
return
}
result = append(result, lastDigit)
}
outputStr := ""
for _, num := range result {
outputStr += strconv.Itoa(num) + "\n"
}
err = os.WriteFile("output.txt", []byte(outputStr), 0644)
if err != nil {
fmt.Println("Помилка при записі у файл:", err)
return
}
fmt.Println("Результат успішно записано у файл output.txt")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment