Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Pass System.String Arguments

Call .NET Methods with System.String Arguments

If an input argument to a .NET method is System.String, you can pass a MATLAB® string. MATLAB automatically converts a char array (string) argument into System.String. For example, the following code uses the System.DateTime.Parse method to convert a date represented by a string into a DateTime object:

strDate = '01 Jul 2010 3:33:02 GMT';
convertedDate = System.DateTime.Parse(strDate);
ToShortTimeString(convertedDate)
ToLongDateString(convertedDate)

To view the function signature for the System.DateTime.Parse method, type:

methodsview('System.DateTime')

Search the list for Parse.

QualifiersReturn TypeNameArguments
StaticSystem.DateTime RetValParse(System.String s)

For more information, see:

Use System.String in MATLAB

This example shows how to use a System.String object in a MATLAB function.

Create an object representing the current time.

dateObj = System.DateTime.Now;
thisTime = ToShortTimeString(dateObj);
class(thisTime)
ans =
System.String

The current time, thisTime, is a System.String object.

To display thisTime in MATLAB, use the char function to convert the System.String object to a MATLAB string.

disp(['The time is ' char(thisTime)]);

More About

Was this topic helpful?