中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-29 08:05
47,816 topics / 349,916 posts / today 0 new / 48,265 members
DOS批处理 & 脚本技术(批处理室) » Intercept text characters
Printable Version  4,214 / 15
Floor1 wyd531 Posted 2007-01-13 00:34
初级用户 Posts 49 Credits 137
To intercept the character "KB832353" in the following paths:

First path: "Microsoft\Updates\Windows Media Player\KB832353"
The part after the last backslash "\" is "KB832353", so you can use string manipulation methods to get the substring starting from the last backslash.

Second path: "Microsoft\Updates\Windows Media Services\KB832359"
Here the relevant part is not "KB832353".

The specific way to intercept depends on the programming language you are using. For example, in Python:

For the first path string, you can do:

path = r"Microsoft\Updates\Windows Media Player\KB832353"
start_index = path.rfind("\\") + 1
kb_number = path[start_index:]
print(kb_number)

This will extract "KB832353" from the first path.

In Java:

String path = "Microsoft\\Updates\\Windows Media Player\\KB832353";
int lastBackslashIndex = path.lastIndexOf("\\");
String kbNumber = path.substring(lastBackslashIndex + 1);
System.out.println(kbNumber);

So the intercepted character "KB832353" can be obtained through such string operation methods.
Floor2 ccwan Posted 2007-01-13 00:48
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
```@echo off
for /f "tokens=4 delims=\" %%i in ('sort/r 1.txt') do set a=%%i
echo %a%
pause>nul
```
Floor3 lxmxn Posted 2007-01-13 00:57
版主 Posts 4,938 Credits 11,386
Floor4 namejm Posted 2007-01-13 22:47
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Using for extension, make a more concise code:

Floor5 ccwan Posted 2007-01-13 23:13
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
The idea of the moderator is very good. If you want to only display KB832353, you need to make some changes.
Floor6 vkill Posted 2007-01-14 03:04
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
%%~nxi This is very good
Floor7 lxmxn Posted 2007-01-14 05:58
版主 Posts 4,938 Credits 11,386

  namejm used this cleverly~
Floor8 applecy Posted 2007-01-14 08:30
初级用户 Posts 78 Credits 168
The method of the 4th floor is good. But if I want to extract the middle part, how about "Windows Media Player" in "Microsoft\Updates\Windows Media Player\KB832353"?
Floor9 namejm Posted 2007-01-14 08:52
荣誉版主 Posts 1,737 Credits 5,226 From 成都
This question has been discussed before. Extracting strings at any level is not a difficult problem. Please see post 14 of this thread: How to get the last part of the filename in the absolute path? .
Floor10 applecy Posted 2007-01-15 09:14
初级用户 Posts 78 Credits 168
Hehe, thanks. Still digesting.

I want to make a small suggestion. I wonder if a bookmarking function can be added? After all, many newbies can't fully grasp everything at once, and it's difficult to find the specified post when they want to check it. With the bookmarking function, everything will be more convenient.
Floor11 zjindong Posted 2007-02-03 14:55
初级用户 Posts 26 Credits 64
There are collections. It's at the bottom of the web page.
Floor12 amao Posted 2007-02-03 16:05
中级用户 Posts 152 Credits 316
@sed "s/ *$//;s/.*\\\(.*\)/\1/" 1.txt
Floor13 amao Posted 2007-02-03 16:10
中级用户 Posts 152 Credits 316
Originally posted by applecy at 2007-1-14 08:30:
The method on floor 4 is good`` but what if I want to extract the middle part?
What about "Windows Media Player" in "Microsoft\Updates\Windows Media Player\KB832353"?


@sed "s/.*\\.*\\\(.*\)\\.*/\1/" 1.txt
Floor14 anqing Posted 2007-02-04 00:03
高级用户 Posts 413 Credits 859
I've learned about the usage of tokens again
Floor15 minmin888 Posted 2007-05-08 13:50
初级用户 Posts 62 Credits 127
Solving one question in multiple ways, learning something!
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023