It is nice on how NET Framework gave a bunch of “shortcut” code, including String.Format. But we have to keep track of the indices in the object array which is not really nice.
It would be good if we just write code, declare a named string collection and format it.
- string format = "my name is [[name]] for it called [[name]] to be noted. and address is [[address]].";
- Hashtable ht = new Hashtable() { { "name", "Minion No. 10594" }, { "address", "gru's place" } };
- txtResult.Text = format.Format(ht);
Now we can use my commonly-used library in rdz.codeplex.com, and use the Format method in StringUtility class. You can download it and use it.
Don’t forget to add reference to Rdz.dll and put using directive as below. You are good to go and the Format function will be available on every string object, like in the example above.
- using Rdz.Utility;
In case you didn’t notice, the hashtable is case-sensitive. So to make it case-insensitive, declare Hashtable as below.
- Hashtable ht = new Hashtable(StringComparer.CurrentCultureIgnoreCase) { { "name", "Minion No. 10594" }, { "address", "gru's place" } };
Cool! See you!
Tidak ada komentar:
Posting Komentar
[give me your ideas, hopes, comments and compliments below...]
[aaand...... +1 if you need to....]