Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using substring and indexOf together

I have a string like this. I need to take after first 8 character until first comma. I tried many things but i can’t figure it out? Could someone help? String comes like this.

"asTyped:fTestManager.Jobs.TestReplications.TestDataReplicationsJob,Version=1.0.0.0,"

I need convert this string to

"TestManager.Jobs.TestReplications.TestDataReplicationsJob"

I’ve tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

string tmp= "asTyped:fTestManager.Jobs.TestReplications.TestDataReplicationsJob,Version=1.0.0.0,";
int tmpLength = tmp.Substring(9).Length;
string test = tmp.Substring(tmp.IndexOf(',') - tmpLength)

I don’t know im trying somethings like this but i can’t make it out. Thank you all.

>Solution :

string str = "asTyped:fTestManager.Jobs.TestReplications.TestDataReplicationsJob,Version=1.0.0.0,";
string result = str.Split(',')[0].Substring(9);

first we split our string with , character with Split(char separator) method, then we get from index 9 to the end using Substring(int startIndex).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading