473,320 Members | 1,979 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,320 software developers and data experts.

whats behind .toString and .parse

5
i was given an assignment to create a pseudocode or a code which will provide an equal function as .toString and .parse (need a code for each) i was wondering if someone might help.
Sep 15 '07 #1
8 1393
pbmods
5,821 Expert 4TB
Heya, Kamhal. Welcome to TSDN!

The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. You have not asked a question. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR
Sep 15 '07 #2
kamhal
5
i dont need an answer i need a guideline from which i can start so far i kinda concluded that parse converts and string casts but i cant figure out the actual thinking behind it. what i need is a rough idea of whats behind them. tostring is simple enough : int i = 0; string b =int i and thats done but for parse is harder since u cant use : string a =A ; int i = string a. the compiler wont let u do it so i was thinking that if u use an if statment ( if a variable is a number it will simply cast it but if u have a string u have to use a different process) and that is what im trying to find out
Sep 16 '07 #3
pbmods
5,821 Expert 4TB
Heya, Kamhal.

parse() and toString() have multiple potential implementations depending on the programming language and context (did you mean PHP's parse_str() built-in? JavaScript's Date::parse() method? Etc.).

Describe the functionality of these two functions to give us a better idea of which ones you are talking about.
Sep 16 '07 #4
kamhal
5
i need its use in c#. after a bit of thinking i guess that the only way to make a script which does the same function i will require to use oop otherwise i have no clue how to make anything similar.
Sep 16 '07 #5
pbmods
5,821 Expert 4TB
Heya, Kamhal.

I'm going to go ahead and move this thread to the .NET forum, where our resident Experts will be better able to help you out.
Sep 16 '07 #6
vanc
211 Expert 100+
i dont need an answer i need a guideline from which i can start so far i kinda concluded that parse converts and string casts but i cant figure out the actual thinking behind it. what i need is a rough idea of whats behind them. tostring is simple enough : int i = 0; string b =int i and thats done but for parse is harder since u cant use : string a =A ; int i = string a. the compiler wont let u do it so i was thinking that if u use an if statment ( if a variable is a number it will simply cast it but if u have a string u have to use a different process) and that is what im trying to find out
Since you said it's alright for ToString, I'll give you an idea about Parse function. Because the function called Parse so it need a Parser to Parse the input parameter. You should create your own Parser and implement all rules to make sure you can parse the right type like Integer or Double for example. When your Parser can not Parse the required parameter, throw exception.
Because this is your assignment, so this is just the lead. Look for Parser, I think you can easily find heaps of them.

Cheers.
Sep 16 '07 #7
kamhal
5
this is what i came up with if u have some sugestions to make it more efficient they are welcome :P

.toString script

Console.Write("Enter a number as an integer: ");
int input = int.Parse(Console.ReadLine());

string result = null;

do
{
int convnum = input % 10;
input = input / 10;

convnum += 48;
byte ascii = (byte)convnum;
char reschar = (char)ascii;

result = reschar + result;
}
while (input != 0);

char quote = '"';
Console.Write("\nThe result as string is: " + quote + result + quote);
Console.ReadKey();
Sep 18 '07 #8
Plater
7,872 Expert 4TB
A pretty decent start, but what if the number is more then 99? You will need to handle those cases too.

What you said about your ToString() probably won't get you any points as it looks like you're just implicitly calling ToString();
int i=4;
string a=i; //this could be implicitly calling the ToString() function.


I will give you what should probably be a big hint. .ToString() and .Parse() (since you're only doing integers) will be pretty much reverses of thmselves, code-wise.

this is what i came up with if u have some sugestions to make it more efficient they are welcome :P

.toString script

Console.Write("Enter a number as an integer: ");
int input = int.Parse(Console.ReadLine());

string result = null;

do
{
int convnum = input % 10;
input = input / 10;

convnum += 48;
byte ascii = (byte)convnum;
char reschar = (char)ascii;

result = reschar + result;
}
while (input != 0);

char quote = '"';
Console.Write("\nThe result as string is: " + quote + result + quote);
Console.ReadKey();
Sep 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
3
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink...
1
by: Fabrice | last post by:
Hello Is it possible to modify CommandArgument property of a LinkButton from vb class (code behind). So, this is my control in my .aspx page : <asp:LinkButton id="strTd"...
1
by: Mythran | last post by:
Dim value As Decimal = 1234.56 Dim format As String = _ "Positive $#,##0.00;Negative $#,##0.00;" Dim s As String = value.ToString(format) Dim d As Decimal = Decimal.Parse(s) The last line...
3
by: Vaidas Gudas | last post by:
I has web project on virtual pc, maked with framework 2.0. there I was used the method role.roleexists("admin") and everything was worked good. but when i replace this project on my local machine,...
4
by: Larry Smith | last post by:
Once you call "ToString()" for an object, how can you then convert the string back to the original object (assuming you know its type of course)? Also, why does "ToString()" produce one string and...
0
by: ADAC | last post by:
I am very familiar with Visual studio 2003 and trying to get a handle on 2005 I can set up the datasource and make it work fine when I databind it to a control like a gridview or details view....
19
by: Steve | last post by:
I have to create 2 strings and then parse one string out to save the data into the database. My first string looks like this: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.