当前位置:网站首页>格式化代码缩进的小技巧
格式化代码缩进的小技巧
2022-08-05 05:25:00 【ProfSnail】
最近这段日子经常混迹于问答板块回答问题,发现了一点小问题。
一些朋友在提问的时候放上来的代码是没有缩进的;或者编程格式不太美观,经常看着看着就迷醉其中了。
提问的兄弟因为自己比较着急,赶紧放上来了一段代码。
自己在这边帮他回答问题,看着代码,也相当着急。今天无意间又发现了一段没有缩进的代码,正好以提问的方式来分享一波。
我简单拿一个这两天帮忙处理的C语言的小程序举例子。我把他变为了无缩进的格式。
BTree createTree(char s[]) {BTNode *p;BTNode *rt;BTNode *lchild, *rchild, parent;stack S;p = (BTNode * )malloc(sizeof(BTNode));p->lchild = NULL;p->rchild = NULL;p->data = s[0];S.push§;rt = p;for(int i = 1; s[i] != ‘\0’; i++){if(‘A’ <= s[i] && s[i] <= ‘Z’) {p = (Node ) malloc(sizeof(Node));p->data = s[i];p->lchild = NULL;p->rchild = NULL;S.pop();S.push§;}if(s[i] == ‘(’) {S.push(NULL);}if(s[i] == ‘,’) {S.push(NULL);}if(s[i] == ‘)’) {rchild = S.top();S.pop();lchild = S.top();S.pop();parent = S.top();S.pop();parent->lchild = lchild;parent->rchild = rchild;S.push(parent);}}return rt;}
这段代码看着就不太想管了,但是想想还是管一管吧。最好用的方法就是将这段代码复制下来,粘贴到VisualStudio里面。
但是对于全部没有空行的代码,VS也处理不了。需要先用Sublime Text处理一下。
Sublime Text Ctrl + H 调出替换界面。搜索分号,将所有的分号替换为分号加换行符(换行符可以使用Ctrl+Enter打出来)。
接下来把这段SublimeText中的代码复制到VisualStudio里面就可以了,VisualStudio会帮忙处理缩进和括号换行的地方了。
大功告成!
平时遇到这种情况,大家是怎么处理的呢?欢迎讨论~
边栏推荐
- BIO, NIO, AIO practical study notes (easy to understand theory)
- Mina disconnects and reconnects
- What is Alibaba Cloud Express Beauty Station?
- 网络层协议介绍
- CIPU, what impact does it have on the cloud computing industry?
- Successful indie developers deal with failure & imposters
- 干货!教您使用工业树莓派结合CODESYS配置EtherCAT主站
- selenium learning
- The highlight moment of operation and maintenance starts with intelligence
- sql server duplicate values are counted after
猜你喜欢
By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
人人AI(吴恩达系列)
传输层协议
The cocos interview answers you are looking for are all here!
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
Transformer详细解读与预测实例记录
Nacos集群搭建
LinkSLA insists that users come first and creates a sustainable operation and maintenance service plan
config.js related configuration summary
随机推荐
VLAN is introduced with the experiment
disabledDate 日期选择器 datePicker
DevOps - Understanding Learning
vscode笔记
May I ask how to read the binlog of the two tables of hologres through flink sql, and then how to join?
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
What's the point of monitoring the involution of the system?
CIPU, what impact does it have on the cloud computing industry?
NACOS配置中心设置配置文件
What are some things that you only know when you do operation and maintenance?
product learning materials
单臂路由实验和三层交换机实验
BIO,NIO,AIO实践学习笔记(便于理解理论)
BIO, NIO, AIO practical study notes (easy to understand theory)
sql server duplicate values are counted after
Wireshark packet capture and common filtering methods
Matplotlib绘图笔记
DevOps流程demo(实操记录)
[ingress]-ingress exposes services using tcp port
NAT experiment