Salesforce Interview Question for Testing / Quality Assurances


Country: United States




Comment hidden because of low score. Click to expand.
4
of 4 vote

public static String ReplaceCharacter(String src,char c) { 
		   StringBuffer sb = new StringBuffer(); 
		   char curr;
		   for (int i = 0 ; i < src.length(); i++) {
		       curr = src.charAt(i); 
		       if (curr != c) 
		          sb.append(curr);
		   }
		   return sb.toString(); 
		}

- pacman February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static String ReplaceCharacter(String src,char c) {
StringBuffer sb = new StringBuffer();
char charArrOfSrc[] = src.toCharArray();
for (char curr:charArrOfSrc) {
if (curr != c)
sb.append(curr);
}
return sb.toString();
}

- Anonymous February 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void Remove(char *str,const char in)
{
if(!(*str))
return;
int len=strlen(str);
int start=0,mid=0;
while(mid<len)
{
if(str[mid]==in)
mid++;
else
swap(str[start++],str[mid++]);
}
memset(str+start,'\0',len-start);
}

- Anonymous February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String removeChar(String value, char deleteChar) {
    int position = 0;
    StringBuffer newString = new StringBuffer();
    while(position < value.length()) {
      char newChar = value.charAt(position);
      if(newChar != deleteChar) {
        newString.append(newChar);
      }
      position++;
    }
    return newString;
}

- trentenward February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public StringBuilder getString(String str, char c)
{
for(int i=0;i<str.length();i++)
{
if(str.charAt(i) != c){
nstr.append(str.charAt(i));
}
}
return nstr;
}

- Anonymous February 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I know my code looks a bit weird. I wanted to play with arrays using arraycopy so just tried to solve this problem using that. And it worked. Any suggestions or improvements will be helpful.

import java.util.*;
import java.lang.*;

class SubStringWithoutCharacter
{
	public static void main(String arg[])
	{
		String s1="google";
		char c='g';
		
		char[] str=s1.toCharArray();
		int i=0;int j=0;
		int count=0;
		char[] temp=new char[str.length];
		int mtemp=str.length;

		while(mtemp!=0)
		{
			if(c == str[i])
			{
				count++;
				i++;
				
				
				if(count<=1)
				{
					temp=new char[str.length-count];
					System.arraycopy(str,i,str,0,str.length-i);
				}
				else
				{
					j++;
					System.out.println("i value " +i+" char "+str[i]);
					System.out.println("Destination index "+j);
					System.out.println("Copying Length "+(str.length - i-count+1));
					if(str.length-i-count+1!=0)
					System.arraycopy(str,i,str,i-count+j,str.length - i-count+1);
					else
					break;
				}
				
				System.out.println("Copying");
				for(int k=0;k<str.length;k++)
				{
					System.out.print(str[k]);
				}
				System.out.println();
			}
			else
			{
				i++;
			}
			
			mtemp--;
			System.out.println("Pass "+mtemp);
		}
		
		String result="";
		for(int cm=0;cm<str.length-count;cm++)
			result=result+str[cm];
		
		System.out.println("Final output "+result);
	}
}

- Akshay Kulkarni March 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String removeChar(String input, char remove) {
        String[] array = input.split(String.valueOf(remove));
        String newString = "";
        for (String a: array) {
            newString+=a;
        }
        return newString;
    }

- george.maggessy April 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String str = "abcdefghcde";
            String find = "cde"; 
            int findcount=0;
                        
                 for(int x = 0; x < str.length()-2; x++) {
                     String checkstr="" + str.charAt(x) + str.charAt(x+1) + str.charAt(x+2);
                     if(checkstr.equals(find)) {
        findcount++;
                     }
      }
       System.out.print(findcount);

- me May 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can any one provide me sample instance to practice here i am ready to pay for him
Please fell free to call me 9700080779

- Mohammed Towfeeq Ali October 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {
    public static void main(String[] args) {
        String str = "google";
        char remove = 'g';

        StringBuilder builder = removeChar(str, remove);

        System.out.println(builder);
    }

    public static StringBuilder removeChar(String str, char remove) {
        StringBuilder builder = new StringBuilder();

        for (char ch:str.toCharArray()) {
            if (ch != remove) {
                builder.append(ch);
            }
        }

        return builder;
    }
}

- chauvd October 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String removeChar(String str, char ch) {

StringBuffer str1 = new StringBuffer();
for (int i = 0; i < str.length(); i++) {

if (ch != str.charAt(i)) {
str1.append(str.charAt(i));
System.out.println(str1.toString());
}

}

return str1.toString();
}

- JainB November 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String removeMe(String mainString, char remove) {
		
		String mainStr = mainString;
		char me = remove;
		
		StringBuffer sb = new StringBuffer();
		
		for (int i = 0; i < mainStr.length(); i++) {
			if (mainStr.charAt(i) != me) {
				sb.append(mainStr.charAt(i));
			}
		}
		return sb.toString();

}

- Anonymous November 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String replace(String str,char c){


String str1="";

int size=str.length();
for(int i=0;i<size;i++){
if(str.charAt(i)!=c){
str1=str1+str.charAt(i);
}

}
System.out.println(str1);
return str1;

}

- sudip January 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String replace(String str,char c){
String str1="";
int size=str.length();
for(int i=0;i<size;i++){
if(str.charAt(i)!=c){
str1=str1+str.charAt(i);
}
}
System.out.println(str1);
return str1;
}

- sudip January 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String removeChar(String input, char ch){
		
		char[] outchar = new char[input.length()];
		int i=0;
		for(char inch:input.toCharArray()){
			if(inch!=ch){
				outchar[i]=inch;
				i++;
			}
		}
		
		
		return new String(outchar);
	}

- Anonymous July 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class class1 {

public static void main(String[] args) {
System.out. println ( remove("google", 'g'));
}

public static String remove (String value, char string){
String newStr = "";
char [] array1 = value.toCharArray();
for (int i=0; i< value.length(); i++ )
{
if ( array1[i] != string)
{
newStr = newStr + array1[i];
}
}

return newStr;

}

}

- Anonymous August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public static string ReplaceChar(string s, char c)
        {
            if (s == null) return null;
            if (c == null) return s;
            
            StringBuilder rStr = new StringBuilder(s.Length);

            for (int i = 0; i < s.Length; ++i)
            {
                if (s[i] != c)
                    rStr[i] = s[i];

            }

            return rStr.ToString();
        }

- iA May 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

with fix ...

public static string ReplaceChar(string s, char c)
        {
            if (s == null) return null;
            if (c == null) return s;
            
            StringBuilder rStr = new StringBuilder(s.Length);
            int j = 0;
            for (int i = 0; i < s.Length; ++i)
            {
                if (s[i] != c)
                    rStr[j++] = s[i];

            }

            return rStr.ToString();
        }

- iA May 21, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More