请帮我删除 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, "");