triozebra.blogg.se

Substring java
Substring java















Static string JavaStyleSubstring(string s, int beginIndex,

SUBSTRING JAVA CODE

When I’m porting Java code to C#, I often use a program defined C# method that simulates how the Java substring method works so I don’t have to deal with indices: But if the first parameter is not 0, the Java and C# functions give different results. Notice that when the first parameter is 0, the Java and C# functions give the same result. The C# call to string u = s.Substring(2,5) means extract 5 characters starting at index 2 so u = “23456”.

substring java

The C# call to string t = s.Substring(0,3) means extract 3 characters starting at index 0 so t = “012”. The C# version of sub-string takes two int parameters that indicate the inclusive start index and the total length of the resulting string. And the Java call to String u = s.substring(2,5) means extract the characters at so u = “234”. The Java call to String t = s.substring(0,3) means extract the characters at indices so t = “012”. For example, suppose string s has 10 characters and is “0123456789”. The Java version of sub-string takes two int parameters that indicate the inclusive start index and the exclusive end index. For example, both languages have sub-string functions to extract a portion of a string, but the functions are slightly different.

substring java substring java

The two languages have many similarities but there are quite a few differences to deal with. It’s not uncommon for me to port C# code to Java, or Java code to C#.















Substring java