leading and trailing
时间: 2023-04-23 21:07:34 浏览: 73
leading和trailing的意思是前导和尾随。在设计和排版中,leading通常指的是行间距,即行与行之间的距离;而trailing则指的是文本末尾与边缘之间的距离。在编程中,leading和trailing也可以指定某些操作的开始和结束。
相关问题
翻译一下function format = stlGetFormat(fileName) %STLGETFORMAT identifies the format of the STL file and returns 'binary' or %'ascii' fid = fopen(fileName); % Check the file size first, since binary files MUST have a size of 84+(50*n) fseek(fid,0,1); % Go to the end of the file fidSIZE = ftell(fid); % Check the size of the file if rem(fidSIZE-84,50) > 0 format = 'ascii'; else % Files with a size of 84+(50*n), might be either ascii or binary... % Read first 80 characters of the file. % For an ASCII file, the data should begin immediately (give or take a few % blank lines or spaces) and the first word must be 'solid'. % For a binary file, the first 80 characters contains the header. % It is bad practice to begin the header of a binary file with the word % 'solid', so it can be used to identify whether the file is ASCII or % binary. fseek(fid,0,-1); % go to the beginning of the file header = strtrim(char(fread(fid,80,'uchar')')); % trim leading and trailing spaces isSolid = strcmp(header(1:min(5,length(header))),'solid'); % take first 5 char fseek(fid,-80,1); % go to the end of the file minus 80 characters tail = char(fread(fid,80,'uchar')'); isEndSolid = findstr(tail,'endsolid'); % Double check by reading the last 80 characters of the file. % For an ASCII file, the data should end (give or take a few % blank lines or spaces) with 'endsolid <object_name>'. % If the last 80 characters contains the word 'endsolid' then this % confirms that the file is indeed ASCII. if isSolid & isEndSolid format = 'ascii'; else format = 'binary'; end end fclose(fid);
这段代码的作用是识别STL文件的格式并返回'binary'或'ascii'。首先打开文件并检查文件大小,如果文件大小为84+(50*n),则该文件可能是ASCII或二进制格式。接着读取文件的前80个字符,并检查第一个单词是否为'solid'。如果是,则该文件为ASCII格式;否则,该文件为二进制格式。最后关闭文件并返回格式。
cmake string trim
CMake does not have built-in functions for trimming strings, but you can use string manipulation functions provided by CMake to achieve this.
Here's an example of how to trim leading and trailing whitespaces from a string using CMake:
```cmake
# Define a string variable
set(myString " Hello, World! ")
# Trim leading whitespaces
string(REGEX REPLACE "^\\s+" "" myString "${myString}")
# Trim trailing whitespaces
string(REGEX REPLACE "\\s+$" "" myString "${myString}")
# Output the trimmed string
message("Trimmed string: '${myString}'")
```
This example uses the `string(REGEX REPLACE ...)` command to replace the leading and trailing whitespaces with an empty string. The regular expressions `"^\\s+"` and `"\\s+$"` respectively match the leading and trailing whitespaces. The `"${myString}"` argument specifies the string to operate on.
Note that this example uses regular expressions to perform the trimming, which may not be the most efficient solution for very large strings. If performance is a concern, you may want to consider using other string manipulation functions provided by CMake, such as `string(SUBSTRING ...)`.