I'm porting existing assets from Java to C #, but there is a bug due to a difference in the specification of the method that cuts out a part of the character string, so make a note for the future.
There are two types of Java and C #. The explanation is a reference citation.
Method | Description |
---|---|
public String substring(int beginIndex) | Returns a string that is a substring of this string. The substring starts at the specified index and ends at the end of this string. |
public String substring(int beginIndex, int endIndex) | Returns a string that is a substring of this string. The substring starts at the specified beginIndex and endsindex-Up to the character in 1. Therefore, the length of the substring is endIndex-It becomes beginIndex. |
Method | Description |
---|---|
public string Substring (int startIndex); | Get the substring from the instance. The substring starts at the specified character position in the string and continues to the end of the string. |
public string Substring (int startIndex, int length); | Get the substring from the instance. This substring is a string with a specified number of characters, starting at the specified character position. |
It may be converted as follows.
Java method | Java code before conversion | After conversion C#code |
---|---|---|
public String substring(int beginIndex) | "String".substring(beginIndex) | "String".Substring(beginIndex) |
public String substring(int beginIndex, int endIndex) | "String".substring(beginIndex, endIndex) | "String".Substring(beginIndex, endIndex - beginIndex) |
It may be converted as follows.
C#Method | Before conversion C#code | 変換後Javacode |
---|---|---|
public string Substring (int startIndex); | "String".Substring(beginIndex) | "String".substring(beginIndex) |
public string Substring (int startIndex, int length); | "String".Substring(beginIndex, length) | "String".substring(beginIndex, beginIndex + length) |
-Java class String # substring -C # String.Substring method
Recommended Posts