public String LongestCommonSubstring(String str1, String str2)
	{
		if ( Strings.IsNullOrEmpty(str1) || Strings.IsNullOrEmpty(str2) )
		{
			return "";
		}

		int[][] num = new int[ str1.length() ][ str2.length() ];
		int maxlen = 0;
		int lastSubsBegin = 0;
		StringBuilder sequenceBuilder = new StringBuilder();

		for (int i = 0; i < str1.length(); i++)
		{
			for (int j = 0; j < str2.length(); j++)
			{
				if (str1.charAt(i) != str2.charAt(j))
				{
					num[i][j] = 0;
				}
				else
				{
					if ((i == 0) || (j == 0))
					{
						num[i][j] = 1;
					}
					else
						num[i][j] = 1 + num[i - 1][j - 1];

					if (num[i][j] > maxlen)
					{
						maxlen = num[i][j];
						int thisSubsBegin = i - num[i][j] + 1;
						if (lastSubsBegin == thisSubsBegin)
						{
							// if the current LCS is the same as the last time this block ran
							sequenceBuilder.append(str1.charAt(i));
						}
						else
						{
							//this block resets the string builder if a different LCS is found
							lastSubsBegin = thisSubsBegin;
							sequenceBuilder.delete(0, sequenceBuilder.length());//clear it
							sequenceBuilder.append(str1.substring(lastSubsBegin, (i + 1) - lastSubsBegin));
						}
					}
				}
			}
		}

		return sequenceBuilder.toString();
	}