SMS sending through ASP.Net API - c#

The SMS Service provider gave a link to send the SMS. this link I put it in my website,But In That Link I have to pass the phone Number and Price dynamically through Label. Can anyone please help Me.
I am Using The Code Which is
var cli = new System.Net.WebClient();
string price = "230";
string number = "9999999999";
cli.DownloadString(#"http://bhashsms.com/api/sendmsg.php?user=ABCXYZ&pass=*****&sender=BSHSMS&phone=9999999999&text=Test SMS YOUR Order HAs Been Placed OF RS. 230 Successfully&priority=ndnd&stype=normal");

Simply put the stuff at the corresponding places in the string to pass to cli.DownloadString(). This examople shows how to do so using string.Format()
var cli = new System.Net.WebClient();
string price = "230";
string number = "9999999999";
var format = #"http://bhashsms.com/api/sendmsg.php?user=ABCXYZ&pass=*****&sender=BSHSMS&phone={0}&text=Test SMS YOUR Order HAs Been Placed OF RS. {1} Successfully&priority=ndnd&stype=normal"
cli.DownloadString(string.Format(format, number, price));

Related

How to correctly format the decimals of a number

I am trying to format the balance received from the Ethplorer API.
(https://github.com/EverexIO/Ethplorer/wiki/Ethplorer-API#get-top-token-holders)
From the API I receive an array of JSON objects with the address, the balance and the amount that address represents for the token
Example:
{"address":"XXX","balance":100000000000000,"share":0.04},...
In the website browser I see that the balance formats them to appear like this (using JS (I have checked the source code and I don't really know what it does))
100000000000000 => 100.000.000,00
254107403768716 => 254.107.403,768716
751685000000 => 751.685,00
679447550000 => 679.447,55
I need them to be formatted in C# in the same way
var balance = 100000000000000;
Console.WriteLine(String.Format("{0:#,##0.00}", balance));
// Output: 100.000.000.000.000,00
Console.WriteLine(balance.ToString("###,###,###"));
// Output: 100.000.000.000.000
// Expected: 100.000.000,00
you've declared long. How do you expect 100.000.000,00? As minimum, you can get 100.000.000.000.000,00
in my culture I get this
Console.WriteLine(100000000000000.ToString(""#,#.00""));
100,000,000,000,000.00
For French I get this
Console.WriteLine(100000000000000.ToString("#,#.00", System.Globalization.CultureInfo.GetCultureInfo("fr-Fr")));
100 000 000 000 000,00
For UK is seem what you need
Console.WriteLine(100000000000000.ToString("#,#.00", System.Globalization.CultureInfo.GetCultureInfo("en-Uk")));
100,000,000,000,000.00
Lets try decimal
var bal = 100000000000000.33m;
Console.WriteLine(bal.ToString("#,#.00", System.Globalization.CultureInfo.GetCultureInfo("en-Uk")));

Unity replace sign in string with text

I have default JSON file with some text.
Here is one line of the json file
"description": "this will add X dollars to your account"
After I read all content of json file and convert it to object(I know how to do this) in my game I want to replace X with some int value, and my new sting should be
int doll = 50;
sting desc = "this will add 50 dollars to your account";
It should be very simple but I new to c#
Thanks
You can use the Replace method if you want to replace all instances of one string with another:
string desc = description.Replace("X", doll.ToString());
Easiest way is to use numbered placeholders that string.Format() uses instead of X.
var myString = "this will add {0} dollars to your account";
myString = string.Format(myString, 50);
Or multiple:
var myString = "This will add {0} dollars to your account number {1}.";
myString = string.Format(myString, 50, "N012345");

Configuring SMS API

Please all I've got this API from an SMS reseller here in Nigeria. I want to know how to insert my textbox values corectly
API: http://smsmobile24.com/components/com_spc/smsapi.php?username=xxx&password=yyy&sender=##sender##&recipient=##recipient##&message=##message##
I need to insert password, username and of course sender and recipients.
I have tried doing this:
string to, msg;
to = smsRecipientBox.Text;
msg = smsMsgBox.Text;
http://smsmobile24.com/components/com_spc/smsapi.php?username=C***er&password=fath****am&sender=Cmanager&recipient = '"+to+"'&message='"+msg+"';
But I get that red line telling me there is an error.
You can't modify a constant value (variable that is marked with const modifier).
You have two options here:
1) you remove the const from the field
2) use formatting to insert values in placeholders in the constant string:
const string url = "http://smsmobile24.com/components/com_spc/smsapi.php?username=C***er&password=fath****am&sender=Cmanager&recipient={0}&message={1}";
var to = smsRecipientBox.Text;
var msg = smsMsgBox.Text;
string result = string.Format(url, to, msg);

using regex to parse a file from a ftpwebrequest

I am reading data from a vendor via an ftpwebrequest in c#. Thus the data will be in a string format line by line e.g
0123030014030300123003120312030203013003104234923942348
I need to parse this data into the appropriate fields so I can then insert them into a sql talble. I know the position each field starts at so I want to use regex to parse each field. This is the function I use to get the data now I just need to parse the data. I am haveing trouble finding a clear solution on how to do so. Any suggestions would be greatly appreciated :)
static void GetData()
{
WebClient request = new WebClient();
string url = "ftp://ftp.WebSite.com/file";
request.Credentials = new NetworkCredential("userid", "password");
try
{
byte[] newFileData = request.DownloadData(url);
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
Console.WriteLine(fileString);
}
catch (WebException e)
{
}
}
You don't need to use a regular expression if you're just splitting at specified lengths. In C# you can just use String.Substring, for example:
byte[] newFileData = request.DownloadData(url);
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
string fieldOne = fileString.Substring(0, n);
Here is an example of regex. We specify what to capture by the totals of \d{x} such as \d{4} gives us 4 digits. Then we place it into a named capture group (?<NameHere>\d{4}) then we access it by its name (NameHere in previous text example) for the processing.
See example with removal of three fields Id, group # and Target numbers:
string data = "0123030014030300123003120312030203013003104234923942348";
string pattern = #"^(?<ID>\d{4})(?<Group>\d{3})(?<Target>\d{8})";
Match mt = Regex.Match(data, pattern);
// Writes
// ID: 0123 of Group 030 on Target: 01403030
Console.WriteLine("ID: {0} of Group {1} on Target: {2}", mt.Groups["ID"].Value, mt.Groups["Group"].Value, mt.Groups["Target"].Value);

Already php sms function convert to C# success

i have already configured SMS gateway & some php code.Now my project is thatone convert it to Csharp with minor changes,
probably i have to write new code.but so.. experienced guys from you i wanted to know is that possible ? Sample code below.
enter code here
$username = "abcdsoft";
$password = "softsoft";
//GET parametrar
//$source = $_GET['sourceaddr'];
//$dest = $_GET['destinationaddr'];
//$message_in = $_GET['message'];
enter code here
$source = $_GET['msisdn'];
$dest = $_GET['shortcode'];
$message_in = $_GET['msg'];
those are most top lines.below code i changed.(php to csharp)
enter code here
string username ='abcdsoft';
string password = 'abcdabcd';
int source = ['sourceaddr'];
int dest = ['shortcode'];
string message_in = ['msg'];
Is this way is correct ?
Almost.
Need to use double-quotes for the string
Request.QueryString is the ASP.NET equivalent to the PHP $_GET.
Also, apparently C# is a bit more strongly typed than PHP, so you need to explicitly convert the query string params to integers.
Code should be like this:
string username = "abcdsoft";
string password = "abcdabcd";
int source = int.Parse(Request.QueryString["sourceaddr"]);
int dest = int.Parse(Request.QueryString["shortcode"]);
string message_in = int.Parse(Request.QueryString["msg"]);

Categories

Resources