Using C#, a string needs to be split into segments of 3037 characters in order t
ID: 3800661 • Letter: U
Question
Using C#, a string needs to be split into segments of 3037 characters in order to be accepted by a REST API. You have a string, description, that is the string needing to be split. And another string, position, that is equal to the current segment position (one-based index). Complete the function below, all code should fit within the ‘return ()’ and take one line.public string getSegmentAt(string description, string position){
return ();
} Using C#, a string needs to be split into segments of 3037 characters in order to be accepted by a REST API. You have a string, description, that is the string needing to be split. And another string, position, that is equal to the current segment position (one-based index). Complete the function below, all code should fit within the ‘return ()’ and take one line.
public string getSegmentAt(string description, string position){
return ();
} Using C#, a string needs to be split into segments of 3037 characters in order to be accepted by a REST API. You have a string, description, that is the string needing to be split. And another string, position, that is equal to the current segment position (one-based index). Complete the function below, all code should fit within the ‘return ()’ and take one line.
public string getSegmentAt(string description, string position){
return ();
}
Explanation / Answer
public string getSegmentAt(string description, string position)
{
return (description.Substring((Convert.ToInt32(position)-1),3037));
}
1. As the position is one based index subtract 1 to get starting position of the current segment.
2. 3037 is the maximum length of current segment.
3. Use Substring to get segment at position provided