China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-15 02:18
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Intercept text characters View 4,027 Replies 15
Original Poster Posted 2007-01-13 00:34 ·  中国 广东 深圳 电信
初级用户
菜鸟
Credits 137
Posts 49
Joined 2006-12-20 04:45
19-year member
UID 74007
Gender Male
Status Offline
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.
我是一只小菜鸟,依呀依呀哟~~~
Floor 2 Posted 2007-01-13 00:48 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
```@echo off
for /f "tokens=4 delims=\" %%i in ('sort/r 1.txt') do set a=%%i
echo %a%
pause>nul
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +6 2007-02-03 21:38
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 3 Posted 2007-01-13 00:57 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

@echo off
for /f "delims=" %%a in (1.txt) do (
Setlocal EnableDelayedExpansion
set a=%%a
set a=!a: =!
echo !a:~-8!
Endlocal
)
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2007-02-03 21:38
Floor 4 Posted 2007-01-13 22:47 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Using for extension, make a more concise code:


@echo off
for /f "delims=" %%i in (1.txt) do echo "%%~nxi"
pause
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
lxmxn +2 2007-01-14 05:57
redtek +5 2007-02-03 21:36
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2007-01-13 23:13 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
The idea of the moderator is very good. If you want to only display KB832353, you need to make some changes.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 6 Posted 2007-01-14 03:04 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
%%~nxi This is very good
Floor 7 Posted 2007-01-14 05:58 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  namejm used this cleverly~
Floor 8 Posted 2007-01-14 08:30 ·  中国 广西 柳州 鱼峰区 电信
初级用户
★★
Credits 168
Posts 78
Joined 2006-12-27 09:58
19-year member
UID 74699
Gender Male
Status Offline
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"?
Floor 9 Posted 2007-01-14 08:52 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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? .
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 10 Posted 2007-01-15 09:14 ·  中国 广西 柳州 电信
初级用户
★★
Credits 168
Posts 78
Joined 2006-12-27 09:58
19-year member
UID 74699
Gender Male
Status Offline
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.
Floor 11 Posted 2007-02-03 14:55 ·  中国 福建 泉州 电信
初级用户
Credits 64
Posts 26
Joined 2006-01-10 16:34
20-year member
UID 48756
Status Offline
There are collections. It's at the bottom of the web page.
Floor 12 Posted 2007-02-03 16:05 ·  美国 北达科他州立大学
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
@sed "s/ *$//;s/.*\\\(.*\)/\1/" 1.txt
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2007-02-03 21:39
Floor 13 Posted 2007-02-03 16:10 ·  美国 北达科他州立大学
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
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
Floor 14 Posted 2007-02-04 00:03 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
I've learned about the usage of tokens again
Floor 15 Posted 2007-05-08 13:50 ·  中国 广东 中山 电信
初级用户
★★
Credits 127
Posts 62
Joined 2007-04-19 12:43
19-year member
UID 85744
Gender Male
Status Offline
Solving one question in multiple ways, learning something!
Forum Jump: