|
First, you have to be respectful of the integer's parents and talk to them about conversion. Then you need to take the integer to church every Sunday so they can talk to the stringy pastor. Most importantly, you cannot force it to convert. It has to be authentic and natural. But, if the integer hangs around enough strings, perhaps one day it'll see the light and realize a character representation of numbers that requires encoding is a much better means of representing data than a number that requires interpretation.
Jeremy Falcon
modified 22-Jan-24 16:25pm.
|
|
|
|
|
So that's where I've been going wrong! if integers go to see the stringy pastor, do floats just float around?
|
|
|
|
|
Floats should go too, but they're stubborn so you'd have to double down.
Jeremy Falcon
modified 22-Jan-24 15:42pm.
|
|
|
|
|
And your point is?
Software Zen: delete this;
|
|
|
|
|
One can mantissapate that response.
Jeremy Falcon
|
|
|
|
|
groan
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Better than mansplaining it, I guess.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
string num = "-5498";
int pos = 0;
int result = 0;
int len = num.Length;
bool neg = false;
if(num[0]=='-') { ++pos; neg = true; }
while(pos<len) {
result*=10;
result = (int)(num[pos]-'0');
++pos;
}
if(neg) result = -1 * result;
something like that?
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Nothing nearly that bomb proof, itoa(), as it a value from a sensor reality has issues if it's negative! (mind you checking to see if it's negative might be an idea... sensor can kick out negative if calibrates wrongly!)
modified 22-Jan-24 15:45pm.
|
|
|
|
|
To be fair, i can break what i wrote by feeding it non-numeric characters. I would say more quick and dirty than bomb proof. itoa() works, but it doesn't stream, which is why I've written the above code more times than i care to admit!
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
OP says "integer to a string".
Did I misread something in that or your code?
And C# already has that for both directions.
|
|
|
|
|
No, I misread something in the OP.
Int to string is even easier.
Edit: C# can't stream to an arbitrary length integer off a textreader for example. That's why I've had to write the parsing code myself.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Wordle 947 5/6
🟨⬜⬜⬜⬜
⬜⬜🟨⬜🟨
⬜🟨⬜🟨⬜
⬜⬜🟩🟩🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 947 4/6*
🟨⬜⬜⬜🟨
⬜🟨🟨⬜🟨
🟩🟨🟨🟨⬜
🟩🟩🟩🟩🟩
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 947 3/6
🟩⬛🟨⬛🟨
🟩🟨🟨🟨⬛
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 947 4/6*
⬜⬜🟨🟨🟨
⬜⬜🟩🟩🟨
🟩⬜🟩🟩⬜
🟩🟩🟩🟩🟩
Happiness will never come to those who fail to appreciate what they already have. -Anon
And those who were seen dancing were thought to be insane by those who could not hear the music. -Frederick Nietzsche
|
|
|
|
|
⬜⬜🟨⬜🟨
⬜⬜⬜⬜⬜
⬜⬜🟩🟩🟨
🟩🟩🟩🟩🟩
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 947 6/6
⬜⬜⬜⬜⬜
⬜⬜🟩⬜⬜
⬜⬜🟨🟨🟨
⬜🟨🟨🟩⬜
⬜🟨🟩🟩🟩
🟩🟩🟩🟩🟩
Phew.
|
|
|
|
|
Wordle 947 4/6
🟨⬛⬛⬛🟨
⬛⬛🟩🟩⬛
⬛🟨🟩🟩⬛
🟩🟩🟩🟩🟩
Ok, I have had my coffee, so you can all come out now!
|
|
|
|
|
Wordle 947 4/6
🟨⬜⬜🟨⬜
⬜⬜🟩🟩🟩
⬜🟨🟩🟩🟩
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 947 3/6
⬛🟨🟨⬛🟨
⬛🟨🟩🟩⬛
🟩🟩🟩🟩🟩
Jeremy Falcon
|
|
|
|
|
Wordle 947 3/6*
🟨🟨⬛⬛🟨
⬛⬛🟩🟩🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
I thought it would have come and gone by now.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
|
seems so
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|