{"id":89,"date":"2022-09-14T22:57:45","date_gmt":"2022-09-14T22:57:45","guid":{"rendered":"https:\/\/mustafauzun.co\/blog\/?p=89"},"modified":"2022-09-15T22:09:04","modified_gmt":"2022-09-15T22:09:04","slug":"how-to-a-string-value-convert-to-number","status":"publish","type":"post","link":"https:\/\/mustafauzun.co\/blog\/how-to-a-string-value-convert-to-number\/","title":{"rendered":"How to convert a string value to a number"},"content":{"rendered":"\n<p>Every programming language has the function of converting string to number.<\/p>\n\n\n\n<p>But do you know how this is done?<\/p>\n\n\n\n<p>Actually, it&#8217;s a very simple process.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>For example to the &#8220;12&#8221; string<\/p>\n\n\n\n<p>In a loop, first, get elements in string convert to ascii code, second, ascii code &#8211; 48 (because, code 48 represents 0 in ascii table), after then result, multiplied by 10 and assigned to variable.<\/p>\n\n\n\n<p>For that case;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10 * variable + (49 - 48)\n10 * 0 (first) + 1\n1<\/code><\/pre>\n\n\n\n<p>And here is another example, write with C#<\/p>\n\n\n\n<p>(Source: <a href=\"https:\/\/gist.github.com\/mrna0\/43dd2056615479bc82db7b3d0088f735\" data-type=\"URL\" data-id=\"https:\/\/gist.github.com\/mrna0\/43dd2056615479bc82db7b3d0088f735\">My Gist<\/a>)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>static int intParse(string value)\n{\n   int newVal = 0;\n   foreach (char letter in value)\n   {\n       newVal = 10 * newVal + (letter - 48);\n   }\n   return newVal;\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Every programming language has the function of converting string to number. But do you know how this is done? Actually, it&#8217;s a very simple process.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[20,19,21],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-c","tag-convert-int","tag-convert-number","tag-string-to-number"],"_links":{"self":[{"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":4,"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/posts\/89\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mustafauzun.co\/blog\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}