#include <oxstd.h>
main()
{
decl s = "npi4", sx = "npi412_s", i1, i2, i3;
// translate character '4' to integer 4
println(s[3] - '0');
// read the integer at position 3
sscan(s[3:], "%d", &i1);
println("i1=", i1);
// read the integer after "npi"
sscan(s, "npi", "%d", &i2);
println("i2=", i2);
// read the integer at position 3 of sx
sscan(sx[3:], "%d", &i3);
println("i3=", i3);
}
prints:
4
i1=4
i2=4
i3=412
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox 5th OxMetrics user conference 2007
oxoxoxox Cass Business School, London
oxoxoxox 20-21 September 2007
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
Nuffield College, Oxford OX1 1NF, UK
tel. UK: +44-1865-278610 fax +44-1865-278621
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Vincent Nijs wrote:
> Hi,
>
> If I have a string such as 'npi4'. How do I get the '4' out of it and into a
> matrix?
>
> I tried x[0][0] = s[3] where x is the storage matrix and s is the string
> 'npi4' but this stores 42. If I use x[0][0] = string(s[3]) the character is
> correct but the value won't get stored in the matrix since it is a string.
>
> What about 'npi412_s'? How get '412' out of that string as an int?
>
> Any ideas? Thanks.
>
> Vincent
>
|