반응형

[javascript] 새로고침 없이 파라미터 제거/수정

 

Remove URL parameters without refreshing page

window.history.pushState({}, document.title, "/" + myNewURL );

https://stackoverflow.com/questions/22753052/remove-url-parameters-without-refreshing-page

 

Remove URL parameters without refreshing page

I am trying to remove everything after the "?" in the browser url on document ready. Here is what I am trying: jQuery(document).ready(function($) { var url = window.location.href; url = url...

stackoverflow.com

 

1- The pushState() method if you want to add a new modified URL to history entries.

2- The replaceState() method if you want to update/replace current history entry.

.replaceState() operates exactly like .pushState() except that .replaceState()

 

For one liner fans, try this out in your console/firebug and this page URL will change:

window.history.pushState("object or string", "Title", "/"+window.location.href.substring(window.location.href.lastIndexOf('/') + 1).split("?")[0]);

This page URL will change from:

http://stackoverflow.com/questions/22753052/remove-url-parameters-without-refreshing-page/22753103#22753103

To

http://stackoverflow.com/22753103#22753103

 

History: pushState() method
https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

 

History: pushState() method - Web APIs | MDN

In an HTML document, the history.pushState() method adds an entry to the browser's session history stack.

developer.mozilla.org

 

History.replaceState() https://developer.mozilla.org/ko/docs/Web/API/History/replaceState

 

History.replaceState() - Web API | MDN

History.replaceState() 메서드는 현재 history를 수정해 메소드의 매개 변수에 전달 된 stateObj, title, URL로 대체합니다. 이 방법은 특히 일부 유저의 동작에 대한 응답으로 history 객체의 상태나 현재 history

developer.mozilla.org

 

반응형
반응형

숫자에 콤마 제거

 

replace comma

금액필드에 , 제거 해야할 경우

 

amount.replace(",", "");

-> only replace one comma

-> 앞에 한개만 제거

 

amount.replace(/,/g, '');

-> replace all comma

-> 모든 콤마 제거

-> 정규식

 

How to replace all of comma

 

Result)

amount = "1,000,000"

 

amount.replace(",", "");

1000,000

 

amount.replace(/,/g, '');

1000000

반응형
반응형

[Java] 문자열 치환(Replace) 사용법 & 예제

String a = "무궁화 삼천리 화려강산 대한사람 대한으로 길이 보전하세 ";	
//replace([기존문자],[바꿀문자])
a= a.replace("대한", "민국");	
System.out.println(a);

//결과값 : 무궁화 삼천리 화려강산 민국사람 민국으로 길이 보전하세
String a = "무궁화 삼천리 화려강산 대한사람 대한으로 길이 보전하세 ";	
//replaceAll([정규식],[바꿀문자])
a= a.replaceAll("대한", "민국");
System.out.println(a);

//결과값 : 무궁화 삼천리 화려강산 민국사람 민국으로 길이 보전하세
반응형
반응형

javascript, nl2br, nl to  


function nl2br(str){  
    return str.replace(/\n/g, "<br />");  
}   

function nl2nbsp(str){   
    return str.replace(/\n/g, "");  
}   
반응형

'프로그래밍 > Script' 카테고리의 다른 글

JSON Editor Online  (0) 2019.11.26
[jQuery] AJAX Cross Origin plugin  (0) 2019.10.21
[jQuery] touch event 체크  (0) 2019.08.19
jQuery 화면전환 효과 참고 사이트  (0) 2019.08.02
[javascript] Switch case else  (0) 2019.07.31
반응형

[JSP] JSTL을 이용하여 개행(줄바꿈)문자를 태그로 바꾸기 ( 줄바꿈,개행,공백, replace 처리 ) 

줄바꿈, 공백 처리


<!-- 상단에 선언 -->
<%
pageContext.setAttribute("CR", "\r");
pageContext.setAttribute("LF", "\n");
pageContext.setAttribute("CRLF", "\r\n");
pageContext.setAttribute("SP", "&nbsp;");
pageContext.setAttribute("BR", "<br/>");
%> 

<!-- jstl로 변환처리 -->
<c:set var="cmt" value="${fn:replace(coment.coment,CRLF, BR)}" />
<c:set var="cmt" value="${fn:replace(cmt,CR, BR)}" />
<c:set var="cmt" value="${fn:replace(cmt,CR, BR)}" />
<c:set var="cmt" value="${fn:replace(cmt,' ',SP)}" />
 

<!-- 화면에 출력하기 -->
<c:out value="${cmt}" escapeXml="false"/> 

 

반응형
반응형

파이썬에서 유니코드 스트림 다루기


# 입력 스트림과 출력 스트림을 연다

input = open("input.txt", "rt", encoding="utf-16")  

output = open("output.txt", "wt", encoding="utf-8")


# 유니코드 데이터 조각들을 스트리밍한다

with input, output:  

    while True:

        # 데이터 조각을 읽고

        chunk = input.read(4096)

        if not chunk:

            break

        # 수직 탭을 삭제한다

        chunk = chunk.replace("\u000B", "")

        # 데이터 조각을 쓴다

        output.write(chunk)



반응형
반응형

[MSSQL]문자열에서 특정문자 개수 알아오기


DECLARE @STR VARCHAR(20)

SET @STR = 'YNYNNNNN'

 

SELECT LEN(@STR)-LEN(REPLACE(@STR,'Y',''))


결과값: 2 (Y가 2번 들어있음)

반응형
반응형

mssql  줄바꿈 치환

 


 REPLACE(REPLACE(CONTENT, char(13) , '' ) ,  char(10), '' ) 





* 줄바꿈, 탭문자 제거 방법(text 타입도 포함)



- 변경 스트링 함수

replace([컬럼명], [변경할 문자], [변경될 문자])


- 엔터, 탭 문자 제거 함수 활용

Tab : char(9)

Line feed: char(10)

Carriage return: char(13)



>엔터 : replace(replace([컬럼명], char(13), ''), char(10), '')

>탭 : replace([컬럼명], char(9), '')

 


 텍스트 타입일 경우, [replace 함수의 인수 1에 대한 인수 데이터 형식 text이(가) 잘못되었습니다.] 에러를 확인할 수 있다.


=> replace(convert(varchar(max), [컬럼명]), [변경할 문자], [변경될 문자])


 

 

반응형

+ Recent posts