Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #258 Convert list of strings to list of integers

Convert the string values from list a into a list of integers b.

integer, allocatable, dimension(:) :: b
  allocate (b(size(a)))
  read (unit=a,fmt=*) b
import "strconv"
b := make([]int, len(a))
var err error
for i, s := range a {
	b[i], err = strconv.Atoi(s)
	if err != nil {
		return err
	}
}
let b = a.map(Number)
classes, systutils, fgl
var
  a: TStringList;
  b: specialize TList<Integer>;
...
for i := 0 to a.count-1 do b.add(IntToStr(a[i]));
b = [int(elem) for elem in a]
b = a.map(&:to_i)
let b: Vec<i64> = a.iter().map(|x| x.parse::<i64>().unwrap()).collect();

New implementation...