Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

substrings length

Tags:

.net

This is kind of a beginner's question but the code I am looking at is in production and I don't want to break anything. So, just in case: isn't

text.Substring(index, length).Length 

is equivalent to just length?

(Except for the potential ArgumentOutOfRangeException.)

like image 987
Nickolodeon Avatar asked Nov 30 '11 17:11

Nickolodeon


People also ask

How many substrings does length N have?

Approach: The count of sub-strings of length n will always be len – n + 1 where len is the length of the given string.

How do you find all substrings in length K?

If the length of a string is N, then there can be N – K + 1 substring of length K. Generating these substrings will require O(N) complexity, and checking each substring requires O(K) complexity, hence making the overall complexity like O(N*K). Efficient approach: The idea is to use Window Sliding Technique.

What is an example of a substring?

Alternatively referred to as substr, a substring is a prefix or suffix of any string. For example, a substring of the word "computer" could be: puter or comp.


1 Answers

Yes, it will be exactly the same.

like image 158
Polynomial Avatar answered Sep 30 '22 21:09

Polynomial