473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

simple math

hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?

it's one of those days...

thanks,
rodchar
Oct 31 '07 #1
6 1124
rodchar wrote:
hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?

it's one of those days...
int newval = int.Parse(value) - 1;

If you want to keep it as a string:

value = (int.Parse(value) - 1).ToString();

Chris.
Oct 31 '07 #2
rodchar <ro*****@discussions.microsoft.comwrote:
hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?

it's one of those days...
You parse it (e.g. int.Parse) and then subtract one. Call ToString() on
the result if you want it back as a string.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 31 '07 #3
rodchar wrote:
hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?
TryParse it to an int, subtract 1, and ToString it back again.

/Søren
Oct 31 '07 #4
Hi,

You cannot do it directly as a string (well you could really).
So first you use Convert.ToInt , do the operation and call to string again:

string number = "123"
number = (Convert.ToInt32( number) + 1 ).ToString();

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?

it's one of those days...

thanks,
rodchar

Oct 31 '07 #5
rodchar wrote:
hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?

it's one of those days...

thanks,
rodchar
If the value is a string ....

int i = Integer.parse(string);
i--;
string = i.ToString();
Regards j1mb0jay
Oct 31 '07 #6
Thanks everyone for showing the many different way to do this.
Rod.

"rodchar" wrote:
hey all,
given:
String value;

how do you subtract 1 from value assuming it's a number?

it's one of those days...

thanks,
rodchar
Nov 1 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: barnesc | last post by:
Hi! Here's a simple hashcash implementation in Python. 28 lines of actual code. Can be reduced to 17 lines for instructional purposes, if you don't want clustering, and use xrange() instead...
20
by: drs | last post by:
Hi, I am trying to find all lists of length x with elements a, b, and c. To this end, I have created the class below, but it is not quite working and I am having trouble figuring out what to...
2
by: Senraba | last post by:
I would like to have a 600 X 400 window open with search results from CPanel's Entropy Search form. I have the following in the <HEAD> tag: <script language="javascript"...
2
by: Webdiyer | last post by:
Hi, We all know that the return value of Math.Log(8,2) is 3,but how about (int)Math.Log(8,2)? On my machine,the return value of (int)Math.Log(8,2) is strange enough! it's not 3 but 2 ! I've...
3
by: vezquex | last post by:
What I want is an element with a shifting background image: <html><head> <script type="text/javascript"> var x = 0 var y = 0 inc = 4 function bgWander(el){ x = x +...
1
by: macklin01 | last post by:
Hi, everybody. I'm trying to do some last cleaning up on the following php page I wrote: http://www.math.uci.edu/~pmacklin/Publications.php This URL parses an XML file of publications: ...
10
by: Ron | last post by:
I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox...
0
by: sean | last post by:
I'm trying to create a "rubber band" rectangle effect on my form. Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles...
5
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
22
by: giordan | last post by:
Hi all! I've wrote this code: <script type="text/javascript"> var largImg; var altImg; var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.