Last active
June 17, 2023 16:03
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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