c# - How to use substring and how to break down one variable into two variables? -


i have been struggling solve problem when used substring.

c# :

string sinput = "vegetable lasgane { receipt: cheese sauce etc...}"; 

what want :

  • remove "{", "receipt:" , "}" using substring
  • then break down sinput new 2 variables such as:

from :

string sinput = "vegetable lasgane { receipt: cheese sauce etc...}"; 

to:

string smeal = "vegetable lasgane"; string sreceipt= "cheese sauce etc..."; 

how in c#? code example apprecaited. thanks!!

just use string.substring , string.indexof methods this;

string sinput = "vegetable lasgane { receipt: cheese sauce etc...}"; string smeal = sinput.substring(0, sinput.indexof('{')); console.writeline(smeal); //vegetable lasgane   string sreceipt = sinput.replace('{', ' ').replace('}', ' '); sreceipt = sreceipt.substring(sreceipt.indexof(':') + 1).trim(); console.writeline(sreceipt);  //cheese sauce etc... 

here demo.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -