請幫我刪除 JSL 中的回車符我有一個 jsl 腳本,它調用 python 檔案來識別來自任何地方的特定目錄。它工作正常,但他的結果有一個破壞一切的馬車性格。
cur_dir = Substr( Get Default Directory(), 2, 999 );
cur_dir = Substitute( cur_dir, "/", "\" );
show(cur_dir);
_path_script = cur_dir || "find_home_directory.py";
show(_path_script);
home_dir = RunProgram(
executable( "python" ),
options( _path_script),
readfunction( "text" )
);
show(home_dir);
home_dir = "C:\dtemp
”;
任何人,你能幫我如何轉換這個字串以刪除回車字符,看起來像這樣嗎?
home_dir = "C:\dtemp"
自動化和腳本編寫回复:請幫我刪除 JSL 中的回車字符下面是我將如何使用 JMP 中的標準轉義字符來實現
names default to here(1);
cr = "\!r";
home_dir = "C:\dtemp
";
show(home_dir);
home_dir = substitute(home_dir, cr, "");
show(home_dir);
哪個給出了結果
home_dir = "C:\dtemp
";
home_dir = "C:\dtemp";
回复:請幫我刪除 JSL 中的回車符是的,終於成功了。 訣竅如下:
假設你有一個文件“example.jsl”並且你想要絕對路徑。 您應該執行以下操作:
cur_dir = Substr( Get Default Directory(), 2 );
cur_dir = Convert File Path( cur_dir, Windows );
Show( cur_dir );
_path_script = cur_dir || "find_home_directory.py";
Show( _path_script );
home_dir = Run Program( executable( "python" ), options( _path_script ), readfunction( "text" ) );
Show( home_dir );
path_to_example_jsl = Substitute( home_dir, "\r", "example.jsl" );
Show( path_to_example_jsl );
您調用的 python 文件很簡單:
import os
def find_home_dir():
cur_dir = os.path.dirname(os.path.realpath(__file__))
while True:
if "file_which_defines_root" in os.listdir(cur_dir):
break
else:
cur_dir = os.path.dirname(cur_dir)
print(cur_dir.strip())
if __name__ == '__main__':
find_home_dir()
回复:請幫我刪除 JSL 中的回車符也許這個?
cur_dir = Substr( Get Default Directory(), 2 );
cur_dir = Convert File Path( cur_dir, Windows );
Show( cur_dir );
_path_script = cur_dir || "find_home_directory.py";
Show( _path_script );
home_dir = Run Program( executable( "python" ), options( _path_script ), readfunction( "text" ) );
Show( home_dir );
home_dir = Substitute( home_dir, "\r", "" );
Show( home_dir );
回复:請幫我刪除 JSL 中的回車字符儘管如果您只是單獨運行這幾行它會起作用。
cr = "
";
home_dir = "C:\dtemp
";
show(home_dir);
home_dir = substitute(home_dir, cr, "");
show(home_dir);
結果:
home_dir = "C:\dtemp
";
home_dir = "C:\dtemp";
回复:請幫我刪除 JSL 中的回車符我試過“(\r)”作為 RegEx 搜索但仍然遇到相同的問題。
cur_dir = Substr( Get Default Directory(), 2, 999 );
cur_dir = Substitute( cur_dir, "/", "\" );
show(cur_dir);
_path_script = cur_dir || "find_home_directory.py";
show(_path_script);
home_dir = RunProgram(
executable( "python" ),
options( _path_script),
readfunction( "text" )
);
show(home_dir);
cr = Regex(home_dir,"(\r)");
home_dir = substitute(home_dir, cr, "");
show(home_dir);結果。
home_dir = "C:\tmp
";
home_dir = "C:\tmp
";
我想要的是:
home_dir = "C:\tmp"
回复:請幫我刪除 JSL 中的回車字符cur_dir = Substr( Get Default Directory(), 2, 999 );
cur_dir = Substitute( cur_dir, "/", "\" );
show(cur_dir);
_path_script = cur_dir || "find_home_directory.py";
show(_path_script);
home_dir = RunProgram(
executable( "python" ),
options( _path_script),
readfunction( "text" )
);
show(home_dir);
cr ="
";
home_dir = substitute(home_dir, cr, "");
show(home_dir);結果還是一樣..:(
home_dir = "C:\dekel_post_processing
";
home_dir = "C:\dekel_post_processing
";
回复:請幫我刪除 JSL 中的回車符@pmroz的解決方案很好! 這是對常見的隱形字符可能出現在一串字符中。 您可以使用轉義序列進行搜索。
回复:請幫我刪除 JSL 中的回車字符cr = "
";
home_dir = "C:\dtemp
";
home_dir = substitute(home_dir, cr, "");