# Transalte Assembly(Solidity)

I want translate code to assembly, but i don't understand , how i can get data from string ( or bytes) Example String: 123 --> uint 123

``````for (uint256 i = 0; i < bytes(_str).length; i++)
{
if ((uint8(bytes(_str)[i]) - 48) < 0 || (uint8(bytes(_str)[i]) - 48) > 9)
{
return (0, false);
}
res = res + (uint8(bytes(_str)[i]) - 48) * (10**(_str.length - i - 1));
}
``````

My try:

``````bytes memory stringNumber = bytes(_str);
assembly
{

function power(level,num) -> result
{
let i:=0x1
result := num
if gt(level,0)
{
for {} lt(i,level) {}
{
result := mul(result,num)
}
}
if eq(level,0)
{
result := 0x1
}

}

let temp

let  level10
for {let i:=0 }
lt(i,lengthStr)
{
temp := sub(data, 0x30)
if or(lt(temp,0x0),gt(temp,0x9))
{
res := 0x0
stop()
}
level10 := power(sub(sub(lengthStr,i),0x1)  ,0xA) //true
}
/* try #2
for {let end := add(data, mul(lengthStr,0x20)) }
lt(data,end)
{
temp := sub(data, 0x30)
if or(lt(temp,0x0),gt(temp,0x9))
{
res := 0x0
stop()
}
level10 := power(sub(lengthStr,sub(ind,0x1))  ,0xA)
}*/

}
``````

I'm beginner, don't hit me strong, please

Solution:

``````function stringToUint256(string memory _str) internal pure returns(uint256 res)
{
bytes memory stringNumber = bytes(_str);
for (uint256 i = 0; i < bytes(_str).length; i++)
{
uint8 codeSymbol = uint8(stringNumber[i]) - 48;
if (codeSymbol < 0 || codeSymbol > 9)
{
return 0;
}
assembly
{