Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-05-27 08:06:01, last edited by 1448 (2015-05-27 14:15:06)

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

[Code] Other way of string into int

Other than the classic Convert.ToInt32(string), I thought of another way to convert a string into an int.

This is what I came up with:

string demo = "45";
public int StringToInt(string demo)
{
	int val = 0;
	for (int i = 0; i <= 1000000; i++)
	{
		if (demo == i.ToString())
		{
			val = i;
			break;
		}
	}
	return val;
}

Disadvantages:

  • Your pc may lag while this takes place if it is slow

  • It can only take values up to the specified index (here, 1 million)

Instead of a nooby method of adding each number and string-ized version of it into an array or dictionary, this can be used.

This is not as efficient as the one provided by Microsoft, but this is just an idea. Not telling anyone to use it.

Offline

#2 2015-05-27 09:17:42

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Code] Other way of string into int

If you're telling yourself it's only worse than the method already implemented, why would you make it or even post it?
Just makes me curious.

Offline

#3 2015-05-27 09:21:01

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Code] Other way of string into int

Idk... Ima nub datz y

Offline

#4 2015-05-27 13:38:51

912468
Member
Joined: 2015-02-21
Posts: 212
Website

Re: [Code] Other way of string into int

This doesn't work, because it is a public string and you return an int...

You will get this error:

Error: Cannot implicitly convert type 'int' to 'string'

vF0MA5o.png

Offline

#5 2015-05-27 13:39:32

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Code] Other way of string into int

Oh... Forgot that //forums.everybodyedits.com/img/smilies/tongue

Offline

#6 2015-05-27 14:09:06, last edited by ewoke (2015-05-27 14:09:47)

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [Code] Other way of string into int

string demo = "45";
public int StringToInt(string demo)
{
	int val = 0;
	for (int i = 0; i <= 1000000; i++)
	{
		for (int j = 0; j <= demo.Length; j++)// where is this used?
		{
			if (demo == i.ToString())
			{
				val = i;
				break;
			}
		}
	}
	return val;
}
string demo = "45";
public int StringToInt(string demo)
{
	int val = 0;
	for (int i = 0; i <= 1000000; i++)
	{
			if (demo == i.ToString())
			{
				val = i;
				break;
			}
	}
	return val;
}

still useless //forums.everybodyedits.com/img/smilies/tongue


if you can read this....good for you

Offline

#7 2015-05-27 14:14:42

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Code] Other way of string into int

lel dez ppl are trying to flame me //forums.everybodyedits.com/img/smilies/tongue

Offline

#8 2015-05-27 14:15:49

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [Code] Other way of string into int

you asked for it


if you can read this....good for you

Offline

#9 2015-05-27 14:17:48

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Code] Other way of string into int

Hidden text

Nope. Don't think I did that.

Offline

#10 2015-05-27 15:43:05, last edited by TiKen (2015-05-27 15:44:38)

TiKen
Member
Joined: 2015-02-24
Posts: 298

Re: [Code] Other way of string into int

alkazam1448 wrote:

Other than the classic Convert.ToInt32(string), I thought of another way to convert a string into an int.

This is what I came up with:

aweful code

Disadvantages:

  • a LOT of disadvantages.

Instead of a nooby method of adding each number and string-ized version of it into an array or dictionary, this can be used.

This is not as efficient as the one provided by Microsoft, but this is just an idea. Not telling anyone to use it.

Could you please think a little bit before you post something. I usually don't get involved with people asking question that can be answered using this wonderful tool called GOOGLE (I thought that people could tell the difference between the EEforums and Google (or even stackoverflow), but I was wrong)

But THIS? It's a whole new level...

So again: Think a bit before posting... Ask yourself if it's really useful. If not, keep it for yourself.

Offline

Wooted by:

#11 2015-05-27 16:04:29

ZeldaXD
EE Homeboy
From: Cyprus
Joined: 2015-02-15
Posts: 1,539
Website

Re: [Code] Other way of string into int

Theres stupid stuff and then theres this topic.


gLjTZE1.png

Offline

#12 2015-05-27 16:31:35, last edited by Tomahawk (2015-05-27 16:35:24)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,824

Re: [Code] Other way of string into int

Let's not post ridiculous code on this forum.

string numberString = "45";
int number;
if (int.TryParse(numberString, out number))
{
    //Continue if parsed successfully;
}

If there was even the slightest chance that this thread wasn't started as a troll, there's no hope for you.

alkazam1448 wrote:

Other than the classic Convert.ToInt32(string)

It gets easier: int.Parse(variable);


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

Wooted by:

#13 2015-05-27 20:54:29, last edited by Zumza (2015-05-27 20:55:22)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,641

Re: [Code] Other way of string into int

Guys, all of you are wrong!
Where humanity will be if all the code will be correctly and efficiently written?
Testers will no longer have a job...
All apps will run faster so CPU fabricants will no longer sell anything because nobody will need stronger processing power.
So I must say "Thanks that you exist Alkazam1448, and you bring more money to our pockets."


Everybody edits, but some edit more than others

Offline

#14 2015-05-27 21:13:39

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [Code] Other way of string into int

Zumza wrote:

Guys, all of you are wrong!
Where humanity will be if all the code will be correctly and efficiently written?
Testers will no longer have a job...
All apps will run faster so CPU fabricants will no longer sell anything because nobody will need stronger processing power.
So I must say "Thanks that you exist Alkazam1448, and you bring more money to our pockets."

Hidden text

if you can read this....good for you

Offline

Wooted by:

#15 2015-05-27 21:29:33

ZeldaXD
EE Homeboy
From: Cyprus
Joined: 2015-02-15
Posts: 1,539
Website

Re: [Code] Other way of string into int

Zumza wrote:

Guys, all of you are wrong!
Where humanity will be if all the code will be correctly and efficiently written?
Testers will no longer have a job...
All apps will run faster so CPU fabricants will no longer sell anything because nobody will need stronger processing power.
So I must say "Thanks that you exist Alkazam1448, and you bring more money to our pockets."

Hidden text

On topic: It has many disadventages and no adventages, don't use it

/thread


gLjTZE1.png

Offline

Wooted by: (2)

#16 2015-06-01 10:43:08

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Code] Other way of string into int

ewoke wrote:
Zumza wrote:

Guys, all of you are wrong!
Where humanity will be if all the code will be correctly and efficiently written?
Testers will no longer have a job...
All apps will run faster so CPU fabricants will no longer sell anything because nobody will need stronger processing power.
So I must say "Thanks that you exist Alkazam1448, and you bring more money to our pockets."

Hidden text
Hidden text

Offline

#17 2015-06-01 22:22:48, last edited by lrussell (2015-06-01 22:58:41)

lrussell
Member
From: Saturn's Titan
Joined: 2015-02-15
Posts: 843
Website

Re: [Code] Other way of string into int

public static int? ToInt(string value)
        {
            for (int i = 0; i < int.MaxValue; i++)
            {
                if (value == i.ToString())
                {
                    return i;
                }
            }

            return null;
        }

It's beautifully inefficient, it's an art. It must be respected!

Offline

lrussell1433193768509218

Board footer

Powered by FluxBB

[ Started around 1711669946.7159 - Generated in 0.083 seconds, 14 queries executed - Memory usage: 1.65 MiB (Peak: 1.87 MiB) ]