function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Devaki Nandan SwamiDevaki Nandan Swami 

how to get size of any string variable ?

I am new to SFDC , I want to get the size of string variable into my apex code . How can i do this?
Best Answer chosen by Devaki Nandan Swami
Amit K AAmit K A
Devaki the same length method you can use .

but on visual force page you can not use method ,so you need to use assosiated poperty "Lenght" inplace of length() method.

All Answers

Amit K AAmit K A
Hi Devaki ,

You can use length function in apex after the srting variable to get the size .

String str1 = "Amit Kumar";
System.debug('str1 length'+str1.length());

 
ClintLeeClintLee
Hi Devaki,

You can use the length() method on any string, provided it's not null.
 
String hello = 'hello';
Integer size = hello.length();

System.assertEquals(5,size);

Hope that helps,

Clint
 
Devaki Nandan SwamiDevaki Nandan Swami
Thanks Amit .

Can you please tell me how can i use the same on visualforce page?
Amit K AAmit K A
Devaki the same length method you can use .

but on visual force page you can not use method ,so you need to use assosiated poperty "Lenght" inplace of length() method.
This was selected as the best answer