0

My string is this:

fileName, callDateTime, sum(callDuration) AS 'Call Duration', callRecorder, equipmentId, errorMessage, extractionDateTime, interactionId, interrupted, extractionSuccess, stitching, bytes, conversionTime, stitchingTime, transferTime, remoteErrorMessage, remoteTransferDateTime, size, remoteTimeToTransfer, extractionStartDate, extractionEndDate, purpose, ruleName, ruleSession, fileOutputFormat, extractedBy, vaultName, vaultType, vaultRemotePath, stitchingTime

I want to remove this part of the text:

"sum (callDuration) AS 'Call Duration',"

I am using this piece of code to try to address this problem:

 var getSumIndex = resultAggOrField.IndexOf($"{rowGroup.AggFunc}");
 var getFieldIndex = resultAggOrField.IndexOf($"'{rowGroup.DisplayName}'");
 var delete = resultAggOrField.Substring(getSumIndex, getFieldIndex);
 resultAgg = resultAggOrField.Replace(delete, string.Empty);

But for some reason, he takes this part of the text:

sum(callDuration) AS 'Call Duration', callRec
2
  • 1
    When you debug, what is the value of rowGroup.AggFunc? Of rowGroup.DisplayName? Of getSumIndex? Of getFieldIndex? Of delete? Basically, which specific operation is producing an unexpected result? Commented Nov 19, 2019 at 20:25
  • Result of the delete variable: "sum(callDuration) AS 'Call Duration', callRec" I want it to be: "sum (callDuration) AS 'Call Duration'," Commented Nov 19, 2019 at 20:30

1 Answer 1

2

Your variable names imply that you misunderstand how the Substring(int, int) method works. The second argument is not an index, it's a length.

Whether you want to hard-code the length for "sum (callDuration) AS 'Call Duration'," or dynamically calculate it (and how you'd dynamically calculate it) is really up to you. But you need to tell the Substring() method the size of the substring to remove, not the ending index of the substring to remove.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.