Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a SMS Software, i want to give Option to Customer to define their own SMS. I give them a text box to write their own SMS which can include database field names Like Dear Customer +CustName+ Thank you for visiting Here, Your Bill Amount is : +BillTotal+ CustNmae And BillTotal is Database Field name and Customer add All Other Field Name which i Show Him to Include. I want to get Field name from String and fill its value and send SMS to Customer. My English is not very well i Hope you understand what i want to say..

What I have tried:

C#
queryacc = "SELECT Id, MessageType, Message, ModifyDate FROM PreDefineMessage where MessageType ='Sale'";
		query = "select * from customer where CustomerCode ='0001'";
		DataTable dtCust = Queries.runSQLCommandDataTable(query);
		DataTable test = runAccessQuerydt(queryacc);
		string messagepreDefine = string.Empty;
		foreach (DataRow  dr in test.Rows )
		{
			messagepreDefine = dr["Message"].ToString ();
			string ff = "Id";
			string f =  "+dr["+ff+"].ToString ()+" ;
			string oldmes = "Dear Customer Your id is : "+dr["Id"].ToString ()+"";
			oldmes = f;
			oldmes =oldmes .Insert (5,f);
			
			oldmes ="Dear customer your id is "	;
		}
		int indexp1 =messagepreDefine .IndexOf ('+');

		 messagepreDefine =messagepreDefine .Insert(indexp1+1, "dr[\"");
		 int indexp2 = messagepreDefine.IndexOf('+',indexp1+1 );
		 messagepreDefine = messagepreDefine.Insert(indexp2 + 1, "");
		foreach (DataRow dr in dtCust.Rows )
		{
			string newmessage = messagepreDefine;
		}
Posted
Updated 24-Mar-16 21:42pm
v2

Try splitting the text by plusses

C#
string() splits = messagepreDefine.split("+");

then your first element splits[0] is the starting text. Your second is field name you can replace. Third element is again text and so on.

Exception: if the text starts with + you need to replace first split. Test and play for a bit, you'll get it.

Alternative: parse with regex - it would go something like this: \\+.+\\+, but this is from memory, you should also tweak and test.
 
Share this answer
 
v2
Comments
Sinisa Hajnal 25-Mar-16 3:41am    
Except it should be single backslash in front of +
Quote:
How to get string name from other string in C#
Basically, you don't, it don't work this way.

The way to do what you want is to define some keywords like +CustName+ or +BillTotal+.
Then for each keyword you have a piece of code.
First you search for the keyword in text and if found, you replace with arbitrary text that you get programmatically.
 
Share this answer
 
v2

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