Given a string eg 500 chars and I want to pick a string between index 400 and index 430. How do you write such a function?
Thanks
Use the string. Substring() method. Like var truncString = longString. Substring(400, 30); .
The Python standard library comes with a function for splitting strings: the split() function. This function can be used to split strings between characters. The split() function takes two parameters.
Java String indexOf() Method The indexOf() method returns the position of the first occurrence of specified character(s) in a string. Tip: Use the lastIndexOf method to return the position of the last occurrence of specified character(s) in a string.
Use the string.Substring()
method.
Like var truncString = longString.Substring(400, 30);
.
Note, that you should check the length of longString
that it is at least 430 chars. If it is not, Substring
will throw an exception.
string x = "aaaa";
string part = x.Substring(400,Math.Min(x.Length,430)-400);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With