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
adi salesforceadi salesforce 

How to create a vfpage to get permutations of string?

Gulafsha MohammedGulafsha Mohammed
Hello,
Refer:
https://javarevisited.blogspot.com/2015/08/how-to-find-all-permutations-of-string-java-example.html

Use this java code in apex and make few changes accordingly. Display the output string in vf.

Mark this as best answer if this has solved your query.

Thanks,
Gulafsha
adi salesforceadi salesforce
Could you write the code
 
Gulafsha MohammedGulafsha Mohammed
Hello Adi,

Vf page:
 
<apex:page controller="StringPermutations">
    <apex:form >
  <apex:pageBlock >
      <apex:inputText label="String" value="{!str}"/>/>
      <apex:commandButton value="Check Permutation values of string" action="{!Permutations}"/>
      <apex:repeat value="{!PermutationList}" var="p">
          <apex:outputText label="Permuted Values" value="{!p}"><br/></apex:outputText>
  	  </apex:repeat>
      </apex:pageBlock>
        </apex:form>
</apex:page>

Controller:
 
public class StringPermutations{
    public String str{get;set;}
    Public List<String> PermutationList{get;set;}
    public void Permutations(){
        PermutationList=new List<String>();
        permutation1(str);
    } 
    public void permutation1(String input){
        permutation('', input); 
        system.debug('PermutationList'+PermutationList);
    } 
     public void permutation(String prefix, String str1) {
    integer n = str1.length();
         if (n == 0){ 
             if(prefix!=null){
     System.debug(prefix);
          PermutationList.add(prefix);
         }
         }
    else {
        for (integer i = 0; i < n; i++)
            permutation(prefix + str1.substring(i,i+1),str1.substring(0, i) + str1.substring(i+1, n));
    }
        
        }
}

Please mark this as best answer if this has helped you.
Regards,
Gulafsha​