Skip to content

Instantly share code, notes, and snippets.

@asdw3276
Created June 18, 2014 18:53
Show Gist options
  • Save asdw3276/bcac142e15ec2b9193e1 to your computer and use it in GitHub Desktop.
Save asdw3276/bcac142e15ec2b9193e1 to your computer and use it in GitHub Desktop.
1.4
public class replacespace{
public static void main(String[] args)
{
String teststring = "Mr John Smith sdfsf sdfs sssf d s";
char[] testchar = teststring.toCharArray();
char[] imput = new char[100];
for(int i = 0; i < testchar.length; i++)
imput[i] = testchar[i];
char[] result = replacespace(imput,testchar.length);
System.out.println(String.valueOf(result));
}
public static char[] replacespace(char[] imput,int length)
{
int count = 0;
for(int i = 0; i < imput.length; i++)
{
if(imput[i] == ' ')
{
count++;
}
}
for(int i = length; i >= 0; i--)
{
if(imput[i] == ' ')
{
imput[i + count * 2] = '0';
imput[i + count * 2 - 1] = '2';
imput[i + count * 2 - 2] = '%';
count--;
}
else
imput[i+count*2] = imput[i];
}
return imput;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment