You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
xpetit 46f4ddc49e
Simplify prompt, execution of Go programs, fix typos
4 years ago
..
README.md Simplify prompt, execution of Go programs, fix typos 4 years ago

README.md

trimatoi

Instructions

  • Write a function that transforms a number within a string in a number represented as an int.

  • For this exercise the handling of the signs + or - has to be taken into account. If one of the signs is encountered before any number it should determine the sign of the returned int.

  • This function will only have to return the int. In case of invalid input, the function should return 0.

  • Note: There will never be more than one sign by string in the tests.

Expected function

func TrimAtoi(s string) int {

}

Usage

Here is a possible program to test your function :

package main

import (
	"fmt"
	piscine ".."
)

func main() {
	fmt.Println(piscine.TrimAtoi("12345"))
	fmt.Println(piscine.TrimAtoi("str123ing45"))
	fmt.Println(piscine.TrimAtoi("012 345"))
	fmt.Println(piscine.TrimAtoi("Hello World!"))
	fmt.Println(piscine.TrimAtoi("sd+x1fa2W3s4"))
	fmt.Println(piscine.TrimAtoi("sd-x1fa2W3s4"))
	fmt.Println(piscine.TrimAtoi("sdx1-fa2W3s4"))
}

And its output :

$ go run .
12345
12345
12345
0
1234
-1234
1234
$