Advertisement
ASP_Volume2 String Manipulation #39593

Java String Replace

This piece of code takes three arguments, you give it a string that you want to do the replace on, what you want to replace, and what you want to replace it with! Simple!

AI

AI 요약: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

소스 코드
original-source
// Example:
// replace("He/\£$llo", "/\£$", " ")
// it will return "He llo"
public static String replace(String checkMe, String toberep, String repwith)
	{
	String temp = checkMe;
	int a = 0;
	try {
			for(int i = 0; i < checkMe.length(); i++) 
			{
				
				a = temp.indexOf(toberep);
				temp = temp.substring(0 , a) + repwith + temp.substring((a + toberep.length()));
				if (a == -1)
				{
				
				break;
				}
			}
		} catch (Exception e) {/*IGNORE*/}		
	
		return temp;
	}
원본 댓글 (3)
Wayback Machine에서 복구됨