Sneha K

Sneha K

  • 1.2k
  • 527
  • 195.5k

How to get particular character position from string usingC#

Jul 31 2017 1:20 PM
Hi, I want to get the position in a string and assign that value to a variable.
 
Eg
 
String PrintType= "3in"
String val ="A4-Format1,A5-Format2,3in-Format3,4in-Format4";
 
Now this is my string. In this i want to find the position of 3in and then i want to find the position of comma(,) of 3in-Format3. Now after getting the first and last position i want to assign that value inside of first and last position to one variable.
 
eg now first postion is 22("3) and the last postion is 3 (3in-Format3(,))is 33.After finding the first and last position i want to assign that value to one variable
 
eg
 
var type = "3in-Format3"
 
Now i find the first postion by
 
String PrintType= "3in"
String val ="A4-Format1,A5-Format2,3in-Format3,4in-Format4";
String a = val.IndexOf(PrintType);
 
Eg if variable a = 3in means in want to get the fromat of 3in
 
eg 3in means i want to get the 3in-format3 value from that string
 
Now i want to find the last position and assign that value between first and last position to variable. I tired my level best to explain my issue. Please any one understand my issue and help me to resolve this issue.
 
Advance Thanks.

Answers (1)