How to refresh the current Android Fragment

To refresh the current Android Fragment you can use the snippet below. The code must be placed inside the Fragment that needs to be updated. The snippet will call the onCreateView Method of the Fragment.

Samples

Sample Java

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to remove specific (unicode) characters in a String using C# and VB.NET

Here is an example on how to remove specific (unicode) characters in a String using C# and VB.NET

Samples

C# Sample

VB.NET Sample

Result

RegexReplaceUnicodeChars

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

Case-Insensitive String.Replace in C# and VB.NET

Here you can find a Case-Insensitive String.Replace method for C# and VB.NET.

Sample C#

public static string ReplaceWithStringComparison(string input, string search, string replace, StringComparison comparison)
{
	var stringBuilder = new StringBuilder();
	var lastIndex = 0;
	var currIndex = input.IndexOf(search, comparison);
	while (currIndex != -1)
	{
		stringBuilder.Append(input.Substring(lastIndex, currIndex - lastIndex));
		stringBuilder.Append(replace);
		currIndex += search.Length;
		lastIndex = currIndex;
		currIndex = input.IndexOf(search, currIndex, comparison);
	}
	stringBuilder.Append(input.Substring(lastIndex));
	return stringBuilder.ToString();
}

Sample VB.NET

Public Shared Function ReplaceWithStringComparison(input As String, search As String, replace As String, comparison As StringComparison) As String
	Dim stringBuilder = New StringBuilder()
	Dim lastIndex = 0
	Dim currIndex = input.IndexOf(search, comparison)
	While currIndex <> -1
		stringBuilder.Append(input.Substring(lastIndex, currIndex - lastIndex))
		stringBuilder.Append(replace)
		currIndex += search.Length
		lastIndex = currIndex
		currIndex = input.IndexOf(search, currIndex, comparison)
	End While
	stringBuilder.Append(input.Substring(lastIndex))
	Return stringBuilder.ToString()
End Function

Please rate this snippet

How to Remove Illegal Filename Characters in C# and VB.NET

To Remove Illegal Filename Characters in C# and VB.NET you can use the following snippet.

Sample C#

public static string RemoveIllegalFileNameChars(string input, string replacement="")
{
	var regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
	var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
	return r.Replace(input, replacement);
}

Sample VB.NET

Public Shared Function RemoveIllegalFileNameChars(input As String, Optional replacement As String = "") As String
	Dim regexSearch = New String(Path.GetInvalidFileNameChars()) & New String(Path.GetInvalidPathChars())
	Dim r = New Regex(String.Format("[{0}]", Regex.Escape(regexSearch)))
	Return r.Replace(input, replacement)
End Function

Please rate this snippet

How to do String Replace in XSL 1.0

To do String Replace in XSL 1.0 you can use the following snippet.

<xsl:template name="StringReplace">
  <xsl:param name="input" />
  <xsl:param name="search" />
  <xsl:param name="replace" />
  <xsl:choose>
    <xsl:when test="contains($input, $search)">
      <xsl:value-of select="substring-before($input,$search)" />
      <xsl:value-of select="$replace" />
      <xsl:call-template name="StringReplace">
        <xsl:with-param name="input"
        select="substring-after($input,$search)" />
        <xsl:with-param name="search" select="$search" />
        <xsl:with-param name="replace" select="$replace" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$input" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

The Template can be invoked as:

<xsl:variable name="newInput">
  <xsl:call-template name="StringReplace">
    <xsl:with-param name="input" select="$input" />
    <xsl:with-param name="search" select="string1" />
    <xsl:with-param name="replace" select="string2" />
  </xsl:call-template>
</xsl:variable>

Please rate this snippet

How to TRIM a string in MSSQL

To TRIM a string in MSSQL you can use the following Userdefinedfunction Snippet.

Sample MSSQL

CREATE FUNCTION dbo.TRIM(@inputString VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@inputString))
END

Please rate this snippet