Click here to Skip to main content
15,867,295 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi is possible converting this code to c#?
JavaScript
function checkSMSLength(event) {
		var text = $(this).val();
		var ucs2 = text.search(/[^\x00-\x7E]/) != -1;
		var sms_price = 0;
		if (!ucs2) text = text.replace(/([[\]{}~^|\\])/g, "\\$1");
		text = text.replace(/\r\n/g, "\n");
		var unitLength = ucs2 ? 70 : 160;
		event.data.$lang.text(ucs2 ? 'فارسی' : 'انگلیسی');
		$(this).css('direction', text.match(/^[^a-z]*[^\x00-\x7E]/ig) ? 'rtl' : 'ltr');
		if (text.length > unitLength) unitLength -= ucs2 ? 3 : 7;
		var count = Math.max(Math.ceil(text.length / unitLength), 1);
		event.data.$counter.text((unitLength * count - text.length) + '(' + count + ')');
		if(event.data.$sms_number.length)
		if(event.data.$sms_number.val()>0){
			var named = event.data.$sms_number.val().search(/^[1-3]000\d+$/) == -1;
			if (named) sms_price = ucs2 ? sms_price_named_fa : sms_price_named_en ;
			else sms_price = ucs2 ? sms_price_fa : sms_price_en ;
			var total = 1;
			if($('#limit_count').length) total = parseInt(fa2en($('#limit_count').val())) || 1 ;
			event.data.$price.text((total * sms_price * count) + ' ریال');
		}else
			event.data.$price.text('_');
	}

pleas help me!
Posted

Try this link - http://www.m2h.nl/files/js_to_c.php[^].
Even if you don't get working code, you will get something that you can take you closer to working code.
 
Share this answer
 
v2
You do it by completely understanding what the javascript code does and rewriting the code in C# to do the same thing. This is probably NOT going to be a statement-for-statement conversion.

If you were looking for someone to do the conversion for you, you've come to the wrong place.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Mar-15 20:33pm    
It's no wonder that some morons down-vote most adequate answers. My 5.
As I want to add just one phrase, I won't add a whole answer. Here is the thing: the notion of "conversion" is not defined for such things; it simply makes no sense, as the whole questions; there is no any practically sensible mapping between C# and JavaScipt; there concepts are different and not compatible.
—SA
Dave Kreskowiak 1-Mar-15 21:33pm    
Too many of these guys downvote because they didn't get copy'n'paste code that worked on the very first try.
Sergey Alexandrovich Kryukov 1-Mar-15 21:44pm    
Exactly...
—SA
Dave Kreskowiak 1-Mar-15 23:08pm    
Case in point... look at Solution 2.
Sergey Alexandrovich Kryukov 1-Mar-15 23:39pm    
Well, this is not really JavaScript, and... I would think thoroughly before calling it "conversion".
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900