Created
March 25, 2014 00:47
-
-
Save bennadel/9752942 to your computer and use it in GitHub Desktop.
ColdFusion Wants You To Access The Underlying Java Methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfset strValue = "This is my ColdFusion string value." /> | |
<cfset strValue = strValue.Trim() /> | |
<cfset strValue = strValue.ReplaceAll( ... ) /> | |
<cfset strValue = strValue.ReplaceFirst( ... ) /> | |
<cfset arrParts = strValue.Split( ... ) /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
Since we don't want to use the Java methods on the | |
string, let's create an actual Java string and then | |
use the methods on that. | |
---> | |
<cfset objString = CreateObject( | |
"java", | |
"java.lang.String" | |
).Init( | |
JavaCast( | |
"string", | |
"I am a ColdFusion string in Java" | |
) | |
) | |
/> | |
<!--- | |
At this point, objString is now a Java String and we | |
can use it's object methods to manipulate the inner value. | |
---> | |
<cfset objString = objString.ReplaceFirst( | |
JavaCast( "string", "ColdFusion" ), | |
JavaCast( "string", "Sexy ColdfFusion" ) | |
) /> | |
<!--- | |
Output the new string value. Convert the Java string | |
to a ColdFusion string using the ToString() method. | |
---> | |
#ToString( objString )# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
Create one Java String object that holds a Java String | |
instance with explicit value. | |
---> | |
<cfset objJavaString = CreateObject( | |
"java", | |
"java.lang.String" | |
).Init( | |
JavaCast( "string", "Hello" ) | |
) | |
/> | |
<!--- Create ont Java StringBuffer object that is empty. ---> | |
<cfset objJavaBuffer = CreateObject( | |
"java", | |
"java.lang.StringBuffer" | |
).Init() | |
/> | |
<!--- | |
Check to see if these JAVA OBJECT are considered simple | |
values or complext objects. They are both created in the | |
same way and should act accordingly. | |
---> | |
IsSimpleValue: #IsSimpleValue( objJavaString )#<br /> | |
IsObject: #IsObject( objJavaString )#<br /> | |
<br /> | |
IsSimpleValue: #IsSimpleValue( objJavaBuffer )#<br /> | |
IsObject: #IsObject( objJavaBuffer )#<br /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment