-1

I'm stuck with the string split functionality in my own project where the case scenario is as follows:

1) I have a formCollection object values which are passed when we send the page to server for manipulation purpose, where I have one field which is decimal with precision of 13 and scale of 2 and I have one JavaScript function which call on onblur event of textbox which return the Input values in currency formatted value. for eg "12500" in "12,500.00" or 130000 in "1,30,000.00"

2) But the thing is that I'm separating the formCollection values by ',' but in this case it is separating the value like:

eg "12,500.00" in "12"

I want the separation from '.00'

My Development Platform is ASP.NET MVC 1.0.

8
  • Looks like you should split on '.', not ','
    – Andrei
    Aug 6, 2013 at 9:21
  • you better explain with your code. can't you change the formCollection value delimiter to something like ||?
    – Damith
    Aug 6, 2013 at 9:24
  • yes i also thinking to implement this way but this is the formCollection varibale ?? can we chage the behaviour of FormCollection values separator...
    – Nik's
    Aug 6, 2013 at 9:34
  • See this is what we are getting the formCollection values after postback is string Variable = "13,23,4469.00;785845,00,988655.00" and its an array so how to implement the spliting functionality with '.00'
    – Nik's
    Aug 6, 2013 at 9:35
  • if i split with '.' then the ',' character will be added to next split and it will throw the casting error while insertion of records in Database
    – Nik's
    Aug 6, 2013 at 9:40

2 Answers 2

0

Are you using the .GetString method?

If I am not mistaken a Formcollection is a namevalue collection. You should be able to get each one by looping through it. For example:

 foreach (var key in formValues.Keys)
 {
     object value = formValues[key.ToString()];
 }

Where in that case formvalues is your formCollection

0

You can use the split method. For more information please go to: https://msdn.microsoft.com/en-us/library/b873y76a(v=vs.110).aspx

Code example:

var example= "12,500.00";
var split= example.Split('.')[0];

This will give you 12,500

Fiddle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.